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

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

The error message I'm obtaining when trying to drop a column:

对象defEmptyString"依赖于列fkKeywordRolleKontakt".

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

消息 5074,第 16 级,状态 1,第 43 行

Msg 5074, Level 16, State 1, Line 43

ALTER TABLE DROP COLUMN fkKeywordRolleKontakt 失败,因为一个或多个对象访问此列.

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

我已经尝试找到默认约束,如下所述:SQL Server 2005 删除列与约束

I have already tried to find the default constraints, as described here: SQL Server 2005 drop column with constraints

不幸的是没有成功:(返回的行是:

Unfortunately without any success :( The line returned is:

fkKeywordRolleKontakt 2 814625945 0 defEmptyString

我无法删除 fkKeywordRolleKontaktdefEmptyString.

摆脱这种依赖的正确方法是什么?

What is the correct way to get rid of this dependency?

也许这也很重要.fkKeywordRolleKontakt 列的类型为 udKeyword (nvarchar(50)),默认为 dbo.defEmptyString.

Perhaps this is of importance too. The column fkKeywordRolleKontakt is of type udKeyword (nvarchar(50)) with default dbo.defEmptyString.


编辑 2:已解决

我现在可以解决问题了.对不起,我没有复制完整的错误信息,它是:

I could solve the problem now. I'm sorry, I did not copy the full error message, which was:

消息 5074,第 16 级,状态 1,第 1 行
对象defEmptyString"依赖于列fkKeywordRolleKontakt".
消息 5074,第 16 级,状态 1,第 1 行
对象FK_tlkpRolleKontakt_tlkpKeyword"依赖于列fkKeywordRolleKontakt".
消息 4922,第 16 级,状态 9,第 1 行
ALTER TABLE DROP COLUMN fkKeywordRolleKontakt 失败,因为一个或多个对象访问此列.

我可以通过右键单击列条目 (dbo.tlkpRolleKontakt > Columns > fkKeywordRolleKontakt)(在 MSSQL Server 管理器中),选择修改"并删除该列来生成一个脚本来删除该列.然后表设计器 >Generate Change Script 生成了必要的命令:

I could generate a script to drop the column by right-clicking on the column entry (dbo.tlkpRolleKontakt > Columns > fkKeywordRolleKontakt) (in MSSQL Server Manager), selecting Modify and deleting the column. Then Table Designer > Generate Change Script generated the necessary commands:

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

就是这样:)

推荐答案

我现在可以解决问题了.对不起,我没有复制完整的错误信息,它是:

I could solve the problem now. I'm sorry, I did not copy the full error message, which was:

消息 5074,第 16 级,状态 1,第 1 行
对象defEmptyString"依赖于列fkKeywordRolleKontakt".

Msg 5074, Level 16, State 1, Line 1
The object 'defEmptyString' is dependent on column 'fkKeywordRolleKontakt'.

消息 5074,级别 16,状态 1,第 1 行
对象'FK_tlkpRolleKontakt_tlkpKeyword' 取决于列'fkKeywordRolleKontakt'.
消息 4922,级别 16,状态 9,第 1 行 ALTER TABLE DROP 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 Server 管理器中),选择修改并删除列.然后 Table Designer > Generate Change Script 生成了必要的命令:

I could generate a script to drop the column by right-clicking on the column entry (dbo.tlkpRolleKontakt > Columns > fkKeywordRolleKontakt) (in MSSQL Server Manager), selecting Modify and deleting the column. Then Table Designer > Generate Change Script generated the necessary commands:

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

相关文章