#0132 – SQL Server – SSMS – Tutorial – Part 07 – Database Administration and maintenance – Productivity enhancing features (L200


The SQL Server Management studio contains many pop-up utilities and tools that help in improving the productivity of our day-to-day database administration and maintenance tasks. While most of these would be implemented using T-SQL code in production, these tools & utilities are a great way to get started. Practice using these tools in your development environments, and then see if they suit your needs for production use.

Copying/Moving a database from one SQL Server instance to another

There are multiple ways to achieve this goal:

  1. Detach/Attach
  2. Backup/Restore
  3. Copy database wizard
  4. Script database wizard

The Detach/Attach and Backup/Restore are fairly common methods, and there is sufficient documentation in Books On Line (hyperlinks embedded above) to get started. However, I rarely see a database administrator using the Copy database wizard or the script database wizard. So, let’s take a look at these two methods.

Copy Database Wizard

The Copy Database wizard is nothing but a customized version of the Attach/Detach method and Integration services under the hood. Perhaps the only hesitation from an administration perspective is that this mechanism requires the SQL Server Agent to be running on the destination server. If you are not a system administrator, you must specify a SQL Server Agent Proxy account that has access to the Integration Services (SSIS) Package execution subsystem.

NOTE: This method is not available for moving system databases. That has to be done via the manual procedures documented on MSDN here.

Here are the brief steps involved in the copying of a database using the copy database wizard.

Right-click the database to copy/move >> Tasks >> Copy Database
Copy Database task option
Welcome page
image

Connect to the source & destination instances. Then select the transfer method. You have a choice between the following:

  1. Detach & Attach method – faster, requires source database to go offline
  2. SMO method – slower, source database remains online

For this demo, I will use the faster, detach-attach method.

image
Choose which databases are to be copied and/or moved.
image
Supply details of the destination database.
image
Choose which objects are to be copied/moved to the new database on the destination instance
image
Configure the SSIS package that would be used to transfer these objects.
image
Choose whether or not to run the transfer immediately
image
Point of no return: Verify the selected options
image
Monitor the progress. At the end of the process, the database has been copied/moved.
image

Script Database Wizard – Script database with data in it!

The above method is great when you can actually connect to both source and destination instances. But what do you do when the destination instance is a remote instance which you cannot connect to? The answer: Generate scripts!

But, generating scripts by default never scripts the associated data, which may be the real point of interest. We need to set a small option to ensure that associated data is scripted.

Right-click the database to copy/move >> Tasks >> Generate scripts
image
Welcome screen
image
Choose whether you need to script all the objects within the database, or script only one.
For demonstration purposes, we will only script one object (keep the check-box unchecked).
image
Choose Script Options: Change the scripting options as necessary by your database coding and deployment standards.

IMPORTANT STEP: Change the “Script data” option from False to True.

image
Choose the object types to script
image
Based on the options selected above, the wizard would ask you to choose the schemas, stored procedures and other objects to script.
image

Choose destination for the scripting process. You can:

  1. Script to File
  2. Script to clipboard
  3. Script to New Query Editor window (default)
image
The required objects are now scripted. Notice the INSERT statements for the pre-existing data.
image
image

You can now use this script to deploy this database on any SQL Server instance for which the script has been generated.

Multi-Sever queries – assisting the discovery process

Whenever I take charge of a server or a couple of servers, I like to know about the databases on the server and about the existing configuration. Not only that, I like to prepare an inventory of the details found, so that I can maintain a change log of whatever changes and tweaks I make going forward. Most of you from the audience would also have such pre-developed scripts that you would be using during the discovery process.

However when taking charge of an entire set of servers, running these scripts against each of these servers is a very time consuming (and depending upon whether you multi-task or not – possibly erroneous) process. SSMS allows us to run a single query against all “registered server” instance from a single window using multi-server query support. You can read more about this feature here: http://beyondrelational.com/blogs/nakul/archive/2011/02/04/multi-server-queries-underappreciated-features-of-microsoft-sql-server.aspx

Practice Exercises…

  • How can you upgrade your SQL Server 2000 database to a SQL Server 2008 database with the copy database wizard?
  • Adjust the options in the script database wizard to generate a database deployment script for your database that confirms to your organization’s standards

Further reading/Other tools & utilities…

Until we meet next time,

Be courteous. Drive responsibly.

Subscribe to my posts via E-mail: Subscribe here | Read my posts via your favourite RSS reader: Click Here! | Tweet to @nakulv_sql

Advertisements

Let me know what you think about this post by leaving your feedback here!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s