views:

114

answers:

1

Whenever I want to add a column to a table it usually goes something like this:

  1. Fire up SQL Server Management Studio (SSMS)
  2. Select "Design" on the table I want to add the column to
  3. Add the new column to the table
  4. Save
  5. Get an error that SSMS can't save because it would need to drop the table (and it can't because the the table has foreign keys on it).
  6. Get frustrated that I forgot that this is something that SSMS can't do
  7. Construct an alter table command by hand to add the column
  8. Move on with life.

This time I am adding a step between numbers 6 and 7. I thought I would ask why SSMS can't make a simple alter table statement to add my new column in.

(In case it matters I am running SSMS 2008 against SQL Server 2008.)

+4  A: 

Alternatively, you can go to Tools-->Options-->Designers-->Table and Database Designers and uncheck "Prevent saving changes that require table re-creation"

Problem solved.

Here's an explanation from MSDN: http://support.microsoft.com/default.aspx/kb/956176.

When you change a table so that you alter the metadata structure of the table, and then you save the table, the table must be re-created based on these changes.

Alison
@Alison: "@KM, he said it generated the drop, but it won't drop due to foreign key constraints. What he(and I) wants to know is why it must drop the table to add a column"
Earlz
Ah, it is listed as "a bug" and they recommend using T-SQL to alter tables and not SSMS..
Earlz
@Earlz: Do you have a link for the "Bug" listing? If so post it as an answer.
Vaccano
@Vaccano, the link in this answer says it's a bug. The bad part is it has affected both 2005 and 2008 and Microsoft still doesn't seem to have intentions of fixing it.
Earlz