How can I generate a script of my database as it is? How can I generate a script of my database as it is? database database

How can I generate a script of my database as it is?


You didn't mention which version of SQL Server, but in SQL 2008 this is very easy

SQL 2008
Expand Databases
Right Click Database
Choose Tasks > Generate Scripts
Generate and Publish Dialog will open
Choose your objects (i.e. Tables, procs, etc)
Click Next On the Set Scripting
Options choose Advanced Options
Under General choose SCRIPT DROP AND CREATE - SCRIPT DROP AND CREATE
Types of Data To Script - Schema and Data
Close Advanced Window
Choose to save to file.


I wrote an open source command line utility named SchemaZen that does this. It's much faster than scripting from management studio and it's output is more version control friendly. It supports scripting both schema and data.

To generate scripts run:

schemazen.exe script --server localhost --database db --scriptDir c:\somedir

Then to recreate the database from scripts run:

schemazen.exe create --server localhost --database db --scriptDir c:\somedir


Try Microsoft SQL Server Database Publishing Wizard. This is a powerful flexible tool for scripting schema / data rom SQL Server.