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?
4条答案
按热度按时间gpnt7bae1#
You can generate scripts to a file via SQL Server Management Studio, here are the steps:
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:
kt06eoxx2#
In the picture you can see. In the set script options, choose the last option: Types of data to script you click at the right side and you choose what you want. This is the option you should choose to export a schema and data
w6mmgewl3#
Have you tried the
Generate Scripts
(Right click, tasks, generate scripts) option in SQL Management Studio? Does that produce what you mean by a "SQL File"?mefy6pfw4#
i wrote this sp to create the schema automatically with all things, pk, fk, partitions, constraints... I wrote it to run in same sp.
IMPORTANT!! before exec
here the SP:
to exec it: