gpt4 book ai didi

sql - 如何在 SQL Server 2008 中删除具有对象依赖关系的列?

转载 作者:行者123 更新时间:2023-12-01 21:59:37 24 4
gpt4 key购买 nike

尝试删除列时收到的错误消息:

The object 'defEmptyString' is dependent on column 'fkKeywordRolleKontakt'.

Msg 5074, Level 16, State 1, Line 43

ALTER TABLE DROP COLUMN fkKeywordRolleKontakt failed because one or more objects access this column.

我已经尝试找到默认约束,如下所述: 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<br/>
The object 'defEmptyString' is dependent on column 'fkKeywordRolleKontakt'.<br/>
Msg 5074, Level 16, State 1, Line 1<br/>
The object 'FK_tlkpRolleKontakt_tlkpKeyword' is dependent on column 'fkKeywordRolleKontakt'.<br/>
Msg 4922, Level 16, State 9, Line 1<br/>
ALTER TABLE DROP COLUMN fkKeywordRolleKontakt failed because one or more objects access this column.

我可以生成一个脚本来删除该列,方法是右键单击列条目(dbo.tlkpRolleKontakt > 列 > fkKeywordRolleKontakt)(在 MSSQL Server Manager 中),选择修改并删除该列。然后表设计器 > 生成更改脚本生成了必要的命令:

ALTER TABLE dbo.tlkpRolleKontakt
DROP CONSTRAINT FK_tlkpRolleKontakt_tlkpKeyword
EXECUTE sp_unbindefault N'dbo.tlkpRolleKontakt.fkKeywordRolleKontakt'
ALTER TABLE dbo.tlkpRolleKontakt
DROP COLUMN fkKeywordRolleKontakt

就是这样:)

最佳答案

您是否先尝试过:

ALTER TABLE <tablename> DROP CONSTRAINT defEmptyString;

关于sql - 如何在 SQL Server 2008 中删除具有对象依赖关系的列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2253185/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com