简体   繁体   中英

Generate SQL scripts in SQL Server Management Studio

I am generating table, view, stored procedure scripts from SQL Server Management Studio 2012.

The options that are set to true are

  1. Check for object existence.
  2. Check for dependent objects.
  3. One file per script.

The objects are being generated in alphabetical order. Is there a way for me to generate the scripts in order of relation, so that when I run the scripts one by one, I will not have key missing errors or object missing errors?

In simple words, I want the scripts to be generated in dependency order, rather than alphabetical order. Is there a way to do it using SQL Server Management Studio 2012.

You can choose to script the entire database by doing the following.

  1. Right click on you already created database.
  2. Click on "Task>Generate Scripts..."
  3. On the "Choose Objects" screen select "Script Entire Database and all database objects", as shown below.
  4. Follow the next steps to save or copy to clip board.

This should script all your tables into one script in dependency order.

脚本生成器

If that still hasn't worked then I suggest you simply reorder your script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM