views:

29

answers:

4

I am using SQL Server 2008 R2.

I have a table which has several fields including a nvarchar(max) field.

When I try and add a new field of type varbinary(max) I get an error message: "Saving changes is not permitted. The change that you have made requires the following tables to be droped and recreated".

Is it possible to have a nvarchar(max) and a varbinar(max) fields in same table?

Is the only way to fix this, to create a new table with the new structure and transfer the data?

+1  A: 

Yes it is possible.

If you are seeing this message you must have tried to insert the new column in the middle of existing ones in the SSMS table designer. Add it onto the end of the existing columns then the table won't have to be completely rebuilt.

Or just execute

alter table YourTable add newcol varbinary(max) null
Martin Smith
@Martin, I undeleted your answer and reverted to the original answer, since this was exactly the problem I was trying to add the field in the middle of existing ones. The "prevent saving changes" also works. Thanks
Shiraz Bhaiji
@Shiraz - Yes for some reason I managed to confuse myself on this one and convince myself that the answer was wrong!
Martin Smith
A: 

SQL Server is not allowing you to evolve the table this way, because it cannot modify the storage for the existing table dynamically. If you want to do this, you have to create a new table with the new schema and populate it with the data from the original table.

Michael Goldshteyn
I don't think this is what's causing the problems.....
marc_s
I guess he just had table recreation turned off and SQL Server has to recreate the table. Good catch!
Michael Goldshteyn
+3  A: 

Yes of course - you probably just have this new "safety" option in SSMS still enabled (it's ON by default):

alt text

That's under Tools > Options ....

marc_s
+1 for beating me to it.
Brad
I've just tested though and with this option turned on you only see the message when SSMS recreates the whole table behind the scenes. If the column is added to the end of the table you don't get this message.
Martin Smith
+1 Thanks, this also works
Shiraz Bhaiji
+2  A: 

Go to Tools | Options > Designers and uncheck the option 'Prevent saving changes that require table re-creation'

Brad