Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot modify table ( using microsoft sql server management studio 2008 )

I create 2 tables and another 1 with foreign keys to the other two.

I realized I want to make some changes to table no 3.

I try to update a field but I get an error "Saving changes is not permitted. The changes you have made require the following table to be dropped and re-created."

I delete those 2 relationships but when I look at dependencies I see my table still depends on those 2 and I still cannot make any change to it.

What can I do?

like image 513
gigi Avatar asked Oct 31 '10 17:10

gigi


People also ask

Why can't I alter a table in SQL Server?

This problem occurs because the Prevent saving changes that require the table re-creation option is enabled by default in SQL Server Management Studio. 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.

How do I modify a table in SQL Server Management Studio?

To modify table data through a view. In Object Explorer, expand the database that contains the view and then expand Views. Right-click the view and select Edit Top 200 Rows. You may need to modify the SELECT statement in the SQL pane to return the rows to be modified.

What is the SQL command to modify a table?

The ALTER TABLE command adds, deletes, or modifies columns in a table. The ALTER TABLE command also adds and deletes various constraints in a table.


2 Answers

You can also enable saving changes that require dropping of tables by going to "tools->options->designers->Table and database designers" and unchecking "Prevent saving changes that require table re-creation"

Be careful with this though, sometimes it'll drop a table without being able to recreate it, which makes you lose all data that was in the table.

like image 166
Doggett Avatar answered Sep 23 '22 00:09

Doggett


When using Microsoft SQL Server Management Studio 2012, the same message occurs. I used the script feature to do modifications which can be seen as a rather good workaround if you wanna use the designer only within a "safe" mode. Especially the GUI related to create a foreign key is not the best in my opinion. When using a script (alter table) for adding a fk, you are faster than using this GUI feature. When adding/writing a 'not' in prior to null, that's not a hard issue. (Removing an 'Allow Nulls' for a column refers to "Saving changes is not permitted" when using the designer.)

like image 43
mnemonic Avatar answered Sep 24 '22 00:09

mnemonic