日期:2014-05-18  浏览次数:20374 次

SQL在表中添加外键不成功!在线等解答
代码:alter table sales 
add constraint FK_sales_customer
foreign key(cust_id) references customer(cust_id)

错误提示:
ALTER TABLE 语句与 FOREIGN KEY 约束"FK_sales_customer"冲突。该冲突发生于数据库"company",表"dbo.customer", column 'cust_id'。


请教各位高手,这是什么问题。。。



------解决方案--------------------
探讨
cust_id在 customer表中是主键,有影响吗??

------解决方案--------------------
外键约束没什么好办法 需要先去掉外键约束 再修改。
------解决方案--------------------
这个语句要想能执行:
1.customer 的 cust_id 列上要建有主键;
2.sales 的 cust_id 列中的数据,要能到 customer 的 cust_id 列中找到,即满足参照完整性.