Why do I get message that the table needs to dropped and re-created when I add/move columns? I believe this happens after adding foreign key constraints.
What can I do to add new columns without dropping table?
Why do I get message that the table needs to dropped and re-created when I add/move columns? I believe this happens after adding foreign key constraints.
What can I do to add new columns without dropping table?
If you're more interested in simply getting SSMS to stop nagging, you can uncheck the "Prevent saving changes that require table re-creation" setting in Options->Designers->Table And Database Designers. The table(s) will still be dropped and re-created, but at least SSMS won't pester you quite as much about it.
(This assumes you're working in an dev/test environment or in a production environment where a brief lapse in the existence of the table won't screw anything up)
Because that's how SQL Server Management Studio does it (sometimes)!
Use TSQL's ALTER TABLE instead:
ALTER TABLE
ADD myCol int NOT NULL
SQL Server (and any other RDBMS, really) doesn't have any notion of "column order" - e.g. if you move columns around, the only way to achieve that new table structure is be issuing a new CREATE TABLE
statement. You cannot order your columns any other way - nor should you, really, since in the relational theory, the order of the columns in a tuple is irrelevant.
So the only thing SQL Server Management Studio can do (and has done all along) is:
The only way to get around this is:
ALTER TABLE
SQL statements instead of the interactive table designer for your workWhen you edit a table definition in the designer, you are saying "here's what I want the table to look like, now work out what SQL statements to issue to make my wishes come true". This works fine for simple changes, but the software can't read your mind, and sometimes it will try to do things in a more complicated way for safety.
When this happens, I suggest that, instead of just clicking OK, click the "Script" button at the top of the dialog, and let it generate the SQL statements into a query window. You can then edit and simplify the generated code before executing it.
There are bugs in SSMS 2008 R2 (and older) that are useful to know:
I reported it few years ago through Microsoft Connect feedback, but bugs were closed due to it is "by design"
Update:
This is strange and irritating to see in desktop product developed during 2 decades, while this (autorefreshing) is being done by most webapplications in any browser
I wasen't allowed to add the column since the column didn't allow "NOT NULL" and therefore when I tried to create the column through the designer or by writing a script, I got the error, you've got.
Instead of "re-creating" the table I just added the column allowing NULL values, populated the column with NON-NULL values and then used the designer (or you can just use a script) to set the column to NOT NULL.
Hope that helps some of you at least.
© 2022 - 2024 — McMap. All rights reserved.