![]() |
|
|
|
By: Atif Shehzad | Read Comments (5) | Related Tips: More > SQL Server Management Studio |
Problem
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

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.

Notes:
Next Steps
| Monday, April 06, 2009 - 10:23:03 AM - DavidB | Read The Tip |
| Nice tip. It is easy to forget that SSMS can generate schema changes for execution later on. | |
| Wednesday, February 29, 2012 - 10:19:12 PM - irv | Read The Tip |
|
consider this script from ssms that changes a table
/* To prevent any potential data loss issues, you should review this script in detail before running it outside the context of the database designer.*/
Let's say there's an error on insert. This script will back out of the insert batch but will run the drop table batch! Have you seen a "best practices" way of modifying these design view generated script to preven tthis? |
|
| Thursday, March 01, 2012 - 4:28:09 AM - Atif shehzad | Read The Tip |
|
@irv- Yes that may be the case as you mentioned. I would point out a couple of points This tip is meant to enable you to store the changes performed through designer as you store changes made through T-SQL. It is just for tracking the changes. However If you are ever interested in executing the generated script then plz consider the warning in the first line of script. It is as under /* To prevent any potential data loss issues, you should review this script in detail before running it outside the context of the database designer.*/ You shoud analyze and change the script for avoiding any data or object loss. Although chances are minimal for scenario that u mentioned. However proper measurements should be ensured as instrcuted. Thanks |
|
| Friday, June 29, 2012 - 3:07:53 PM - Rafay | Read The Tip |
|
hi want to compare and update the schema automaticaly without any third party tool in sql server 2005 i am new in the feild and i cant find any thing without thirdparty tool on google can you guide me in it... Waiting for your reply.. Regards, Rafay.. |
|
| Monday, July 02, 2012 - 2:35:46 AM - Atif | Read The Tip |
|
@Rafay. You may generate the tables, columns, or views by using the tables/views like INFORMATION_SCHEMA.TABLES , sys.columns etc. Once compared through the scripts you may modify the objects as required. Also have a look at following couple of helpful links http://www.mssqltips.com/sqlservertip/2089/sql-schema-comparison-with-visual-studio-2010/ http://msdn.microsoft.com/en-us/library/dd193250.aspx Thanks |
|
|
privacy | disclaimer | copyright | advertise | about authors | contribute | feedback | giveaways | user groups Some names and products listed are the registered trademarks of their respective owners. Edgewood Solutions LLC | MSSharePointTips.com | MSSQLTips.com |