我通过以下方式创建了一个外键(在 SQL Server 中):
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 失败,因为一个或多个对象访问此列
我已经尝试过了,但它似乎不起作用:
alter table company drop foreign key Company_CountryID_FK;
alter table company drop column CountryID;
我需要做什么才能删除该CountryID
列?
谢谢。