Skip to content
Advertisement

Export database schema into SQL file

Is it possible in MS SQL Server 2008 to export database structure into a T-SQL file?

I want to export not only tables schema but also primary keys, foreign keys, constraints, indexes, stored procedures, user defined types/functions.

Also I don’t want the data to be present in this T-SQL file.

Is there any way to achieve that?

Advertisement

Answer

You can generate scripts to a file via SQL Server Management Studio, here are the steps:

  1. Right click the database you want to generate scripts for (not the table) and select tasks – generate scripts
  2. Next, select the requested table/tables, views, stored procedures, etc (from select specific database objects)
  3. Click advanced – select the types of data to script
  4. Click Next and finish

MSDN Generate Scripts

When generating the scripts, there is an area that will allow you to script, constraints, keys, etc. From SQL Server 2008 R2 there is an Advanced Option under scripting:

enter image description here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement