| How to move a database |
|
DBAs are always asked to move database from one instance to another, make a copy of database on the same instance, change database files location etc. This requires from dba full understanding of what a database consists of and what a database depend on. The article gives a step by step instruction of how move database, copy database or change database files locations. How to copy a databaseThis describes how to create a copy of a database with a different name but the same contents on the same sql server instance. The easiest and safest method is backup-restore using GUI - SQL Server Management Studio or Enterprise manager for SQL Server 2000 and below versions. Right click on the database you want to copy -> Tasks -> Backup
A dialog window will show up. Leave all options default and click Add to add backup file, for instance choose C:\Backup directory and mydb.bak file name. After the backup task is completed click on Databases node under you sql server instance main node, right click and choose Restore Database... In To database field type the future name of your copy databas. Under Specify the source and location of backup sets to restore choose From device radion button and click ... button
In showed up dialog click Add and find your backup for instance C:\backup\mydb.bak, click OK. Mark Restore Checkbox for the file you have added. Now you may need to verify file names and locations on Options page. Click OK when finished. How to move database on the same instance In other words how to change location of some or of all database files (data files, log files and full-text catalogues). 1. Make full backup of the database you want to move and of master database. 2. Get the file list for the database including physical location and logical name 4. Set the database OFFLINE: 7. Set the database ONLINE: 8. Verify the new locations for the files: You could simply detach database, move the files and full-tezt catalogues and then attach database. But in case you set database offline its data cache and procedure cache are not dropped so after setting it back online it will still have non-empty caches which might be critical for production databases. Moving database to another sql server instanceYou should consider such things as logins, jobs, ssis packages, replication etc when planning to move your database to a new server. 1. Make full backup of the database to be moved and master database. 2. Get the list of data/log files and full-text catalogues for the database including physical location and logical name
USE master 5. Copy data and log files and full-text catalogues (taken on step 2) to the new server location. 6. Attach the database on the new intance using CREATE DATABASE Transact-SQL statement with FOR ATTACH clause: Review the output script carefully and select the logins you need to move (those returned by sp_change_users_login sp). Run the revised login creation script on destination sql server instance The described methods apply to SQL Server 2000, SQL Server 2005 and SQL Sever 2008.
Comments (0) |