Collaborate Chapter 9 Querying, Managing, and Administering Databases Using SQL Server 2005 9.3 ¤NIIT In this section, you will learn about: Linked servers Types of replication Monitoring and improving replication performance Resolving conflicts in merge replication Recovering from a failure in replication Using KILL statement Read the following topic in the Appendix of the book Administering Databases Using SQL Server 2005: Working with Linked Servers Read the following topic in the section Replicating Data of Chapter 7 of the book Administering Databases Using SQL Server 2005: Identifying the Types of Replication Read the following topic in the section Managing Replication of Chapter 7 of the book Administering Databases Using SQL Server 2005: Monitoring and Improving Replication Performance Read the following topic in the section Managing Replication of Chapter 7 of the book Administering Databases Using SQL Server 2005: Resolving Conflicts in Merge Replication Knowledge Byte Linked Servers Identifying the Types of Replication Monitoring and Improving Replication Performance Resolving Conflicts in Merge Replication ¤NIIT 9.4 Querying, Managing, and Administering Databases Using SQL Server 2005 Read the following topic in the section Managing Replication of Chapter 7 of the book Administering Databases Using SQL Server 2005: Recovering from a failure in replication The KILL statement is used to terminate a process on the basis of the session ID. The KILL statement can also be used to terminate a normal connection, which internally terminates the transactions that are associated with the specified session ID. The syntax for using a KILL statement is: KILL { session_ID } [ WITH STATUSONLY ] where, session_ID is the session ID of the process to be terminated. Session_ID is a unique integer that is assigned to each user connection when a connection is established. The session ID value is tied to the connection for the duration of the connection. When the connection ends, the integer value is released and can be reassigned to a new connection. WITH STATUSONLY is used to generate a progress report about a specified session ID. KILL WITH STATUSONLY does not terminate or roll back the session ID. This command only displays the current progress of the rollback process. To display the current session ID you can use @@SPID procedure. You can also retrieve information on active session ID values by querying the session_id column of the sys.dm_exec_sessions, sys.dm_exec_requests and sys.dm_tran_locks dynamic management views. The following example shows how to terminate a session with session ID 98: KILL 98 The following example generates a status of the rollback process for the specific session ID: KILL 98 WITH STATUSONLY Recovering from a Failure in a Replication Using KILL Statement Querying, Managing, and Administering Databases Using SQL Server 2005 9.5 ¤NIIT This section contains: Best practices Tips and tricks FAQs The following best practices can be considered while replicating databases in SQL Server 2005: Program your application to use the stand by server in case of a database failover: If your database server is implementing the replication mechanism, it is a good practice to program your application in such way that it uses a standby server if your database server is not available. This is because replication exclusively does not provide a mechanism to fail over from one server to another standby server. Back up the replication databases regularly: Replication databases should be backed up on a regular basis. In addition, the ability to restore those backups should also be tested periodically. The following databases should be backed up regularly: z The publication database z The distribution database z The subscription databases z The msdb database at the Publisher, Distributor, and Subscribers servers. z The master database at the Publisher, Distributor, and Subscribers servers. Validate data periodically to verify the replication between Subscriber and Publisher: Validation is not required by replication, but it is recommended to run validation periodically for transactional replication and merge replication. Validation allows you to verify that data in the Subscriber server matches data in the Publisher server. Successful validation indicates that all changes made in the Publisher server have been replicated in the Subscriber server at a specified time and that the two databases are synchronized. The following tips and tricks will help you use import and export utilities in SQL Server 2005: When the bcp utility is connecting to SQL Server with a trusted connection by using integrated security, use the -T option (trusted connection) instead of the user name and password combination. From the Expert’s Desk Tips and Tricks Best Practices ¤NIIT 9.6 Querying, Managing, and Administering Databases Using SQL Server 2005 While using the bcp utility do not use a blank password. Use a strong password such as MySoN 8N i$ 3 yeeR$ old or M$8ni3y0. While using the bcp utility, if the file name includes a space or quotation mark at the command prompt, enclose the identifier in quotation marks (""). The following example illustrates the use of quotation marks in a bcp command: bcp db1.Events.Place out "Events Places.dat" -T -c Do you need to stop an activity on a database when it is published? No, an activity can continue on a database while a publication is being created. When is a subscription available? A subscription is available after a snapshot has been applied to the subscription database. What recovery model is required on a replicated database? Replication functions properly by using any of the recovery models: simple, bulk- logged, or full recovery model. Does replication encrypt data? No, replication does not encrypt data that is stored in the database or transferred over the network. Does replication resume if a connection is dropped? Yes. If a connection is dropped, the replication process resumes at the point at which it stopped. FAQs Querying, Managing, and Administering Databases Using SQL Server 2005 9.7 ¤NIIT 1. Which edition of SQL Server 2005 allows database snapshots? a. Standard edition b. Enterprise edition c. Express edition d. Workgroup edition 2. You want to create a database snapshot. Which command will you use with the AS SNAPSHOT OF clause to create a snapshot of a database? a. CREATE SNAPSHOT b. ALTER DATABASE c. ALTER SNAPSHOT d. CREATE DATABASE 3. Which task cannot be performed with respect to database snapshots? a. Create multiple snapshots of a database. b. Drop files from a database snapshot. c. Create a table through a snapshot. d. Create a snapshot on the same server instance as the source database. 4. Which command reverts back a database from a snapshot? a. RETRIEVE DATABASE <db1> FROM DATABASE_SNAPSHOT=<Sn1> b. RESTORE DATABASE FROM DATABASE_SNAPSHOT=<Sn1> c. RESTORE DATABASE <db1> FROM DATABASE_SNAPSHOT=<Sn1> d. RETRIEVE DATABASE FROM DATABASE_SNAPSHOT=<Sn1> 5. Which method is used to query against a linked server? a. openlink() method b. openquery() method c. createquery() method d. createlink() method Challenge ¤NIIT 9.8 Querying, Managing, and Administering Databases Using SQL Server 2005 1. Which of the following is the publisher in replication implementation by using SQL Server 2005? a. Database server that replicates the data and database objects b. Database objects that are to be replicated c. Database data that is replicated d. Database server that takes the publication 2. Which of the following creates the snapshot of data in the primary server? a. Replication job b. Database server c. Distributor d. Replication agent 3. Which replication agent transfers the changes made to the publication from the distributor to the subscribers? a. Snapshot agent b. Distributor agent c. Log reader agent d. Merge agent 4. Which replication job detects replication agents that are not actively logging history? a. Agent history clean up b. Distribution clean up c. Expired subscription clean up d. Replication agent checkup 5. Which type of replication is used to replicate data that does not change frequently? a. Merge replication b. Transaction replication c. Snapshot replication d. Distribution replication 6. Consider the following stages of a replication process: a. Configuring a publisher and distributor b. Identifying a publication c. Initializing replication Which stage is missing in the preceding list of stages of a replication process? i. Creating and initializing the publisher ii. Creating and initializing subscriptions iii. Creating subscriptions Home Assignment Querying, Managing, and Administering Databases Using SQL Server 2005 9.9 ¤NIIT iv. Initializing subscriptions 7. Which type of publication allows both the publisher and subscriber to update data independently? a. Transactional publication b. Snapshot publication c. Merge publication d. Transactional publication with updatable subscriptions 8. What is the default value for the replication latency threshold? a. 35 seconds b. 32 seconds c. 40 seconds d. 30 seconds 9. Which statement is not true with regard to the BCP utility? a. It is a command line utility. b. It is used to copy the SQL Server data to or from an operating system data file. c. It provides the BCP GET and BCP SET operations. d. BCP parameters are casesensitive. 10. Which of the following tool/command is not used to import and export data in SQL Server 2005? a. SSIS Tool b. BCP Utility c. OPENROWSET Function d. Bulk Import Tool ¤NIIT 9.10 Querying, Managing, and Administering Databases Using SQL Server 2005 . Collaborate Chapter 9 Querying, Managing, and Administering Databases Using SQL Server 2005 9. 3 ¤NIIT In this section, you will learn about: Linked servers Types of replication . Replication Knowledge Byte Linked Servers Identifying the Types of Replication Monitoring and Improving Replication Performance Resolving Conflicts in Merge Replication ¤NIIT 9. 4 Querying,. Working with Linked Servers Read the following topic in the section Replicating Data of Chapter 7 of the book Administering Databases Using SQL Server 2005: Identifying the Types of Replication