如何删除 SQL Server 中的外键? [英] How do I drop a foreign key in SQL Server?

查看:76
本文介绍了如何删除 SQL Server 中的外键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过以下方式创建了一个外键(在 SQL Server 中):

I have created a foreign key (in SQL Server) by:

alter table company add CountryID varchar(3);
alter table company add constraint Company_CountryID_FK foreign key(CountryID) 
references Country;

然后我运行这个查询:

alter table company drop column CountryID;

我收到此错误:

消息 5074,级别 16,状态 4,第 2 行
对象Company_CountryID_FK"依赖于CountryID"列.
消息 4922,级别 16,状态 9,第 2 行
ALTER TABLE DROP COLUMN CountryID 失败,因为一个或多个对象访问此列

我已经试过了,但它似乎不起作用:

I have tried this, yet it does not seem to work:

alter table company drop foreign key Company_CountryID_FK; 
alter table company drop column CountryID;

我需要怎么做才能删除 CountryID 列?

What do I need to do to drop the CountryID column?

谢谢.

推荐答案

尝试

alter table company drop constraint Company_CountryID_FK


alter table company drop column CountryID

这篇关于如何删除 SQL Server 中的外键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆