我正在尝试这个SQL语句一次从两个表中删除,但我发现它只是从一个表中删除并给我一个错误
DELETE语句与REFERENCE约束冲突" FK__cc_custom__custo__02084FDA"。冲突发生在数据库" CurtainClub",table" dbo.cc_customer_address",column' customer_number' .`
我的sql语句如下:
BEGIN
SELECT * from cc_customer
inner join cc_customer_address on customer_id=customer_number
delete from cc_customer where customer_id=3
delete from cc_customer_address where customer_number=3
END
另请注意,customer_number
是customer_id
答案 0 :(得分:1)
您应该交换DELETE
语句:
BEGIN
SELECT *
from cc_customer
inner join cc_customer_address on customer_id=customer_number;
delete from cc_customer_address where customer_number=3; -- first child
delete from cc_customer where customer_id=3; -- then parent
END