110 Appendix•SelfTestAppendix Making either of these changes will not stop the activated stored procedures from continuing to process. These settings simply stop any new instances of the activated stored procedures from being started. If you attempt to change the PROCEDURE_NAME setting to an invalid procedure name the ALTER QUEUE command will fail with an error message, because only valid procedure names can be used. 16. You are creating new Service Broker objects for a new SQL Service Broker application. The IT department coding standards require that when contracts are defined you must specify the message type used for the source and destina- tion. You are creating your new services and are defining your message types. Which code block is the correct code block to use? A. CREATE CONTRACT YourContract AUTHORIZATION dbo SourceMessageType SENT BY ANY, DestinationMessageType SENT BY ANY; B. CREATE CONTRACT YourContract AUTHORIZATION dbo SourceMessageType SENT BY INITIATOR, DestinationMessageType SENT BY ANY; C. CREATE CONTRACT YourContract AUTHORIZATION dbo SourceMessageType SENT BY INITIATOR, DestinationMessageType SEND BY TARGET; Answer C is the correct solution. Although answers A and B will correctly create the contract, those two code samples do not meet the IT department coding standards, which require that contracts are defined with specific definitions so that the message type can be used by only one side of the application. 17. You are seeing performance problems on your SQL Server Service Broker application. Messages are taking too long to be processed by the activated stored procedure. The stored procedure itself is already fully optimized. What can you do in order to decrease the amount of time it takes to process messages with the least amount of effort? A. Increase the number of parallel processes that are run automatically by changing the MAX_QUEUE_READERS value via the ALTER QUEUE command. B. Increase the number of parallel processes that are run automatically by the receiving service by changing the MAX_QUEUE_READERS value via the ALTER SERVICE command. SelfTestAppendix•Appendix 111 C. Reduce the number of messages by sending more data per message. D. Create more queues and send some of the messages to each of the queues. The correct answer is A. You will want to use the ALTER QUEUE command to increase the number of threads that are run in parallel. If you already have set this to the maximum number of threads, then you could consider answer D, but it is not likely that you will ever need to make this change. 18. You have two instances on a server that need to be able to send messages between the instances. Your corporate IT policies say that SQL Service Broker Endpoints must be created on TCP port 5600. You create and bring online the first Endpoint, but you cannot get the second Endpoint to come online. What should you do to correct the issue? A. Add a second IP to the server. Configure the first instance to use the first IP for the Endpoint, and the second instance to use the new IP for the Endpoint. Start the Endpoint on the second instance. B. Change the port number of the second instance to a different port number using the ALTER QUEUE command and bring the Endpoint online. C. Restart the SQL Server instance that has the Endpoint that will not come online. D. Use the ALTER ENDPOINT command with the FORCE_ONLINE switch to force the Endpoint to come online. The correct answer is A. Because your IT policy states that the Service Broker Endpoint must be created on TCP port 5600, a second IP address must be added to the server so that each Endpoint can have its own IP to listen on. Restarting the instance will not help bring the Endpoint online as the port number is locked by the other instance. There is no FORCE_ONLINE switch for the ALTER ENDPOINT command. 19. You are defining new SQL Service Broker objects. Your messages must contain XML data, but there are several different schemas that can be used that will be identified by the receiving process by querying the XML document within the message body to identify which code branch to use. What validation method should you use when creating the Message Type? A. NONE B. EMTPY C. WELL_FORMED_XML D. VALID_XML WITH SCHEMA COLLECTION 112 Appendix•SelfTestAppendix Answer C is correct. You should select the WELL_FORMED_XML. The VALID_XML WITH SCHAMA COLLECTION option requires a single XML schema be defined. Because your requirement is that different XML schemas can be sent, but you want to ensure that the XML is valid, the WELL_ FORMED_XML option is the correct answer. 20. You have a SQL Service Broker application that you wish to increase the performance when receiving messages. What changes should you make? A. Change the receiving code to load the data into a table, increasing the number of messages being received at one time by increasing the value of the TOP parameter. B. Change the sending code to send more than one message in the same conversation. Change the receiving code to load the data into a table, increasing the number of messages being received at one time by increasing the value of the TOP parameter. C. Change the sending code to send more than one message in the same conversation. D. Increase the number of activated procedures that can run at any one time. Answer B is the correct answer. You have to change both the sending code and the receiving code to increase this performance. Increasing the number of activated procedures will not increase the performance of the RECEIVE command so that is not a good solution. Chapter 13: Performance Tuning 1. You’re the DBA for a sales and marketing organization who have a high rate of data change (lots of INSERTS and DELETES). Over the past few weeks the SQL server has gradually become slower. Which DMV could help identify the cause? A. Sys.dm_os_schedulers B. Sys.dm_os_slow_tasks C. Sys.dm_db_index_physical_stats D. Sys.dm_exec_requests The correct answer is C. Since there’s a high data churn, it’s possible that index fragmentation is the cause; the index physical stats will confirm whether SelfTestAppendix•Appendix 113 this is the case. Problems with the SQLOS schedulers are unlikely to get progressively worse. The DMV in Answer B does not exist. The DMV in Answer D shows currently executing tasks and will be less useful when investigating gradual server slowdown. 2. Which of the following could be used within a function by Resource Governor to classify incoming sessions? A. IP Address B. Username C. Server Role Membership D. Hostname The correct answers are A, B, C, D. All options could be used within a UDF to classify incoming sessions. 3. You’ve recently enabled Resource Governor to ensure the Finance and HR departments each receive a fair share of CPU and memory on a consolidated SQL Server. Since Resource Governor has been operating, some users have experienced connection timeouts and you suspect the classifier function may be the cause. How could you identify the cause? A. Run SQL Profiler B. Connect using Dedicated Admin Connection C. Capture Performance Monitor data D. Reboot the server and see if problem recurs The correct answer is B. Connections using Dedicated Admin Connection (DAC) are now exposed to the session classification so a problem with the UDF used for classification will not be experienced by a DAC connection. SQL profiler trace may help, but isn’t the fastest method. There are no performance monitor counters to help with this situation. Rebooting will not prove the cause of the problem. 4. You’re troubleshooting a slow running problem and you’d like to see which indexes, if any, are being used by the slow query. You’re configuring a SQL profiler trace. Which events should you include to see the actual execution plan in XML? A. Showplan XML Statistics Profile B. SQL:BatchCompleted 114 Appendix•SelfTestAppendix C. Showplan XML D. RPC:Completed Answer A is correct. The Showplan XML Statistics Profile event will capture the actual execution plan. Showplan XML captures the estimated plan and this may be different from the actual plan. Neither option in Answer B or D will capture any plan. 5. Users complain that the database server is slow to respond or causes timeouts, and you’ve been running a server-side trace capturing details of query perfor- mance. The server is busy and you’ve generated 10 × 1 GB trace files. What’s the best way to find queries with the longest duration? A. Open each trace file in Profiler and find longest duration. B. Open the trace in Excel and sort by duration. C. Use fn_trace_gettable to load the data into a table, analyze with TSQL queries. D. Run the trace again with a filter. The correct answer is C; load the trace data into a table and query this table. Answer A is incorrect; although possible, this will be difficult, time consuming, and error prone, so it isn’t the best option. Excel can’t read SQL trace data natively. No trace filter is available for worst performing queries. 6. You’re responsible for maintenance for a mission-critical database that is 650 GB in size, with a particularly large sales order table. The nightly index maintenance scripts are fully optimized but regularly run longer than the maintenance window. How could you resolve this with minimal impact to the business? A. Delete old data from the sales order table. B. Separate sales data into separate databases, one for each calendar year. C. Don’t carry out index maintenance. D. Implement table partitioning. The correct answer is D. Table partitioning is well suited to address this requirement. Options A, B, and C will all impact the business. 7. You’re responsible for managing a database that uses table partitioning for a stock trading firm. Performance on the partition storing most recent trades has started to degrade and you’d like to begin a new partition. Which statement should you use? . correct the issue? A. Add a second IP to the server. Configure the first instance to use the first IP for the Endpoint, and the second instance to use the new IP for the Endpoint. Start the Endpoint. Endpoint on the second instance. B. Change the port number of the second instance to a different port number using the ALTER QUEUE command and bring the Endpoint online. C. Restart the SQL Server. not help bring the Endpoint online as the port number is locked by the other instance. There is no FORCE_ONLINE switch for the ALTER ENDPOINT command. 19. You are defining new SQL Service Broker