我有一个 SQL 数据库表,其中有 35 条现有记录。该表中的字段之一称为 Name
、nvarchar(100)
、not null
但是,由于最近的更改,我需要使该列可为空。
当我在 SQL Server Management Studio 中更改列以允许空值并保存更改时,出现以下错误:
不允许保存更改。您所做的更改需要
以下表格将被删除并重新创建
如何允许自动删除并重新创建该表?
I've got a SQL Database Table, which has 35 existing records. One of the fields in this table is called Name
, nvarchar(100)
, not null
However, due to a recent change, I need to make this column nullable.
When I change the column to allow nulls in SQL Server Management Studio, and go to save my changes, I get the following error:
Saving changes is not permitted. The changes you have made require the
following tables to be dropped and re-created
How can I allow this to automatically be dropped and re-created?
发布评论
评论(3)
我找到了解决方案。转到“工具 > 选项 > 设计器 > 表和数据库设计器”:
I've found the solution. Go to "Tools > Options > Designers > Table and Database Designers":
这是 SSMS 中的设置。
工具 - 选项 - 设计器 - 防止保存需要重新创建表的更改
It's a setting in SSMS.
Tools - Option - Designers - Prevent saving changes that require table re-creation
我也遇到了同样的问题;想要为以前不允许的列允许空值。请考虑 MS 的警告,不要关闭此选项:
http://support.microsoft.com/kb/956176
以及他们使用 Transact-SQL 的建议解决问题,例如
alter table MyTable alter columns MyDate7 datetime NULL
这为我解决了这个问题。
I had the same problem; wanting to Allow Nulls for a column that previously did not. Consider MS's warning to NOT turn off this option:
http://support.microsoft.com/kb/956176
And their recommendation to use Transact-SQL to solve the problem, e.g.
alter table MyTable alter column MyDate7 datetime NULL
This solved it for me.