Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 script to restore database from a BAK file

Author  Topic 

nitya
Starting Member

1 Post

Posted - 2009-11-02 : 03:59:56
Hi,
I am new to SQL server and have been creating/restoring databases using the management studio. I need a script to create multiple databases which will initially contain the same data which I have as a BAK file. Can the following script be used without any issues?
Is there any room for improvement? The restore statement was generated by the SS management studio when i restored another database.

I actually need to create 30plus databases on the same sql server using the same BAK file and I am looking for a clean script that can be used in production for one time use.
I dont understand the prefic "N" used in the restore statement.any help with that also will be of great help.
This script works on my development machine but want to make sure if this is the right way.

RESTORE DATABASE [test-sg-scipt2] FROM  DISK = N'C:\Dist\Data.bak' WITH  FILE = 1,  MOVE N'ARC' TO N'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\test-sg-script2.mdf',  MOVE N'ARC_log' TO N'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\test-sg-script_2.ldf',  NOUNLOAD,  REPLACE,  STATS = 10

RESTORE DATABASE [test-sg-scipt3] FROM DISK = N'C:\Dist\Data.bak' WITH FILE = 1, MOVE N'ARC' TO N'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\test-sg-script3.mdf', MOVE N'ARC_log' TO N'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\test-sg-script_3.ldf', NOUNLOAD, REPLACE, STATS = 10

thanks in advance.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-11-02 : 10:56:15
You can ignore the "N". It's just there to represent unicode data. You aren't using unicode data, so it can be removed. I just leave it in there though as it doesn't hurt anything.

The script looks good.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -