尝试删除列时收到的错误消息:
对象“defEmptyString”依赖于列“fkKeywordRolleKontakt”。
消息 5074,第 16 层,状态 1,第 43 行
ALTER TABLE DROP COLUMN fkKeywordRolleKontakt 失败,因为一个或多个对象访问此列。
我已经尝试找到默认约束,如下所述: SQL Server 2005 drop column with constraints
不幸的是没有任何成功:(返回的行是:
fkKeywordRolleKontakt 2 814625945 0 defEmptyString
而且我无法删除fkKeywordRolleKontakt
和中的任何一个defEmptyString
。
摆脱这种依赖的正确方法是什么?
编辑:也许这也很重要。fkKeywordRolleKontakt 列的类型为 udKeyword (nvarchar(50)),默认为dbo.defEmptyString
.
编辑2:解决
我现在可以解决问题了。对不起,我没有复制完整的错误信息,它是:
Msg 5074, Level 16, State 1, Line 1
The object 'defEmptyString' is dependent on column 'fkKeywordRolleKontakt'.
Msg 5074, Level 16, State 1, Line 1
The object 'FK_tlkpRolleKontakt_tlkpKeyword' is dependent on column 'fkKeywordRolleKontakt'.
Msg 4922, Level 16, State 9, Line 1
ALTER TABLE DROP COLUMN fkKeywordRolleKontakt failed because one or more objects access this column.
我可以通过右键单击列条目 (dbo.tlkpRolleKontakt > Columns > fkKeywordRolleKontakt)(在 MSSQL 服务器管理器中),选择修改并删除列来生成一个脚本来删除列。然后 Table Designer > Generate Change Script 生成了必要的命令:
ALTER TABLE dbo.tlkpRolleKontakt
DROP CONSTRAINT FK_tlkpRolleKontakt_tlkpKeyword
EXECUTE sp_unbindefault N'dbo.tlkpRolleKontakt.fkKeywordRolleKontakt'
ALTER TABLE dbo.tlkpRolleKontakt
DROP COLUMN fkKeywordRolleKontakt
就是这样 :)