SQLTeam.com | Weblogs | Forums

Generate Scripts Question


I know how to generate scripts in the Management Studio BUT I want to generate ALTER scripts ...not CREATE or DROP & CREATE. I have lots of tables and stored procedures I send to developers I work with and generating the scripts is a pain in the.... am I missing something? Seems generating ALTER scripts should be easy.


So it seems ALTER TO scripting isn't available for tables?? ...I have lots of computed coloum code in some tables so what does one do? Document all the changes by hand and send in an e-mail? Should be an easier way.


I may have misunderstood your question, but, if you simply want ALTER instead of CREATE, you can do a global replace on "CREATE TABLE " to "ALTER TABLE " (and similar replaces for PROCEDUREs etc.) in the script that you generate.

The only difference between an alter script and a create script for an object is the keyword ALTER or CREATE.


THanks but it apparently isn't that simple ....simply changing CREATE to ALTER bombs when executed. This works in views and stored procedures but not tables.


You are right. For tables you cannot simply alter the table as a whole. You can alter most columns or other properties of the table, but replacing create with alter wouldn't work.

Given that SQL Server does not let you alter a table as a whole like stored procedures, what would be the use case scenario even if you write an alter script?


Is using Schema Compare in Visual Studio or Red Gate's software an option? That's how we do all of the alters needed to get an environment synched with the changes.