Auto generate change scripts in SQL Server Management Studio (SSMS) for tables
2009-04-20 16:40
573 查看
Auto generate change scripts in SQL Server Management Studio (SSMS) for tables
Written By: Atif Shehzad -- 4/6/2009 -- 1 comments Stay informed - get the MSSQLTips.com newsletter and win - click here |
As a part of my best practices, I always save the T-SQL scripts used for creation and modification of objects in SQL Server. When creating and modifying tables using SQL Server Management Studio designer it is easy to right click in the designer and select "Generate Change Script...", but is there a way to automatically script the creation and/or modification of tables made through of SQL Server Management Studio (SSMS) designer? This tip shows you an option that exists within SSMS to automatically generate these scripts for all table changes when using the table designer.
Solution
Within SQL Server Management Studio (SSMS) there is an option to automatically generate scripts for your changes done through the GUI. The solution for this problem is provided in SSMS and works with both SQL Server 2005 and SQL Server 2008, but by default this option that we will discuss is disabled.
To enable the option
From the SSMS menus click on "Tools"
Click on "Options..."
Click on "Designers"
Check the checkbox "Auto generate change scripts" as highlighted below
After checking the specified checkbox, SSMS is now able to generate scripts for the creation and/or modification of any table when you use the designer.
Testing It Out
Let's confirm the script generation for the creation of a new table.
In SSMS select a database and expand the tree
Right click on the tables folder inside and click on "New Table".
A designer will appear for the creation of new table.
Create a single column for this table, I have created a column named TestCol1 as nchar(10)
Save the new table and give the table a name and click OK
Another window will popup that includes the actual script for creating this new table as shown below
Click on "Yes" to save the script and you will be prompted to specify the location. The file name by default will be the name of the table such as "tableName.sql", but this can be changed to anything you like.
If you do not want to save the script then click "No", clicking "No" will not roll back the implemented changes, but the script will not be saved
Notes:
It is important to mention here that unchecking the box in this frame as highlighted above "Automatically generate change script on every save" will cause this change to be undone in the options that we first configured.
Also scripts are not automatically generated for deletion of a table
While working on views through designers no script is generated, however the code for views operation is provided inside the designer and may be copied and saved.
Next Steps
By implementing script auto generation for your SSMS designer you will be able to save changes made through designers easily, which will allow you to have change scripts for changes made through SSMS designer.
相关文章推荐
- SQL server Management Studio Express auto generate change script
- Problem to create "New Database Diagram" in Microsoft SQL Server Management Studio for SQL Server 2012
- sql express 2008 - Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instan
- SQL Server Management Studio 2016 (SSMS)
- SQL Server Management Studio(SSMS)的使用与配置整理(不定期更新 2016/02/04)
- Sql Server2008 中的SQL Server Management Studio(SSMS)
- Sql Server2008 中的SQL Server Management Studio(SSMS) (转)
- Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection
- 在SQL Server Management Studio (SSMS)中使用字体颜色
- SQL Server Management Studio 2008 (ssms) 安装
- Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection
- Sql Server Management Studio 辅助工具(SSMS代码格式化)
- Restore DataBase In SQL Server Management Studio
- SQL Server Management Studio 2016 (SSMS)
- Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection
- Microsoft SQL Server Management Studio -- Restore database in a difference server
- Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.
- How to build an OLE DB application for SQL Server CE in Visual Studio 2005
- SQL Server Management Studio(SSMS)如何批量删除表?
- Stored procedures to implement paging for large tables or queries in SQL Server 2005 and SQL Server 2008