7

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?

2 Answers 2

11

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;
Sign up to request clarification or add additional context in comments.

3 Comments

Is this available in SSMS Express too? I'm not sure if I'm missing something, but I can't find that option!
@lainie yes Use Management Studio Express (available separately or as part of Express advanced) which has the Backup option on the right click menu for each database under Tasks.
@lainie Make sure both servers have the same collation settings. If you restore from a server with a case sensitive collation to a server with a non case sensitive collation annoying errors can happen when joining with temporary tables for example.
5

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 :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.