Friday 23 May 2014

SQL Server generate database script sql

Generating the script

Here is a step by step guide to generate an sql script to re created a database in SQL Server using SQL Server Management Studio (SSMS). This can be used to copy the database structure and contents, or for backups.


  1. Right click the database to be the source of the script, select "Tasks", select "Generate Scripts.."
  2. Select specific objects to be included, else select "Script entire database and all database objects" radio button. 
  3. The default is to generate the schema only, if data is required as well/instead of then select advanced options and alter "Types of data to script" to the desired setting.
  4. Set desired location to save the script and click next
  5. Review the settings to be used and click next
You now have an SQL script to recreate your database.

Restoring the database

To create your database from the SQL script simply select File -> Open ->  File, select the script.


From the toolbar click execute


The database should be be fully restored.