Friday, May 16, 2014

Restore Database from SQL scripts.

I recently had to move a database from one server to another, using SQL Server Management Studio.
I first made use of Generate Scripts to create these SQL files.


  • Right click the database you want to generate scripts for (not the table) and select tasks - generate scripts
  • Next, select the requested table/tables, views, stored procedures, etc (from select specific database objects)
  • Click advanced - select the types of data to script
  • Click Next and finish
http://msdn.microsoft.com/en-us/library/hh245282.aspx


I chose to create the schema on its own, and then the data on its own, one file per table.
Even though the largest SQL files was no larger than 100Mb, SQL Server management Studio was still complaining and running out of memory.

So instead I opted to use the SQLCMD tool, which is leaner, faster, and does not complain of memory issues

This is how I used it.

sqlcmd -S ServerName -i Script.sql -o DbLogFile.log

http://technet.microsoft.com/en-us/library/ms162773.aspx

No comments: