19
votes

Script table as - ALTER TO is greyed out - SQL SERVER 2005 and sql server 2008. Is there any way to enable this>? or do we still write the alter command to alter any table?

It seems ALTER using right click on the object is only applicable to SPs and functions

2
The problem is, there are so many different options when it comes to altering a table. For a SP or function, even if you're just changing one line, the entire body has to be repeated - so scripting ALTER PROCEDURE is a useful thing to do. Contrast this with a table, where the ALTER may be ADDing a column or constraint, ALTERing a column, DROPing a column or constraint, etc. What is it going to usefully put in the scripted ALTER TABLE command, beyond the words ALTER TABLE and the table name?Damien_The_Unbeliever
If it is always disabled (grayed out) they should simply remove that option instead of making people wonder way it is. It is kind of like a street sign saying "Right turn on Purple Only" when there are only red/yellow/green lights, that would be a pretty useless sign.Mark Schultheiss
At least it's consistent. When I right click a stored procedure and do "Script Stored Procedure as..." all the CRUD options (SELECT/UPDATE/DELETE/etc) are there, but greyed out.Tab Alleman

2 Answers

16
votes

This command is not available for tables (but is for the other objects). The alternative is either to use "Design" from the same menu, or to write down your own change scripts. I'd definitely recommend to avoid the designer.

7
votes

ALTER TO does not work for tables. You can however use Design to enter the Table Designer. When you are done with the changes you can either apply them directly or use Generate Change Script to get the SQL that SSMS would use when applying the changes you have made in the designer.