开发者

Export database from one SQL Server to another SQL Server

I have a test database that I need to export into开发者_开发百科 our client's test environment.

This will be a one time only job.

I'm using SQL Server 2005 (My test db is SQL Server 2005 Express)

What is the best way to do this?


Easiest Way

Backup the database in SSMS, and then restore the database on the target machine.

To do this in SSMS (SQL Server Management Studio), right click the database you want to backup select Tasks->Backup, note the type of backup and the path of the .bak file. Then grab that file (the .bak) and go to the target database server / machine. Right click databases and do a "Restore".

Here you can tell it the path of the .bak file, and the database will be created on your clients machine with the name you specify.

Harder But Reusable Way

If you really feel geeky you can write some T-SQL to backup and restore the database as well. Let me know if you feel real geeky and we can go this route as well...but it appears you are only doing this once so scripting is probably some overkill. But just in case anyone needs to backup a database, you can throw this in a procedure if you want:

DECLARE @strRootPath varchar(50)
DECLARE @BackupFile varchar(100)
DECLARE @strDB varchar(25)

SELECT @strRootPath = 'C:\SQL_BACKUPS\MyDBFolder\'
SELECT @strDB = db_name()

SELECT @BackupFile = 
      @strRootPath
    + db_name()
    + '_'
    + CONVERT(varchar(8), GetDate(), 112)               -- yyyymmdd
    + '_'
    + REPLACE(LEFT(CONVERT(varchar(8), GetDate(), 108), 5), ':', '')    -- hh:mm:ss
    + '.BAK'

BACKUP DATABASE @strDB TO  DISK =@BackupFile WITH RETAINDAYS = 10, NAME = N'MyDB_DATA-Full Database Backup', STATS = 10

BACKUP LOG MyDB
   TO MyDB_Log;


or maybe you can use SQL Server Management Studio (SSMS) then right click on database that you want to export so you will get new window for export-import database. fill any information for database connection and follow the steps until you success export it :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜