DELETE语句与REFERENCE冲突 [英] The DELETE statement conflicted with the REFERENCE
问题描述
我有一个带有客户ID的table_Project(链接到tbl_Customer).在tbl_Customer中,我有Customer_ID(作为密钥)和其他一些信息,例如电话,电子邮件等.
I have a table_Project with a CustomerID in it (linked to tbl_Customer). In tbl_Customer I have Customer_ID(as key) and some other info like Phone, Email etc.
要从Gridview中删除它,请使用以下DeleteCommand:
To delete it from the Gridview I use this DeleteCommand:
DeleteCommand="DELETE FROM [tbl_Customer] WHERE [Customer_ID] = @Customer_ID"
但这给了我以下错误:
DELETE语句与REFERENCE约束"Klant_Relatie"冲突.数据库"Database_1",表"dbo.tbl_Project","CustomerID"列中发生了冲突.该语句已终止.
但是通过更新CustomerInfo我没有得到任何错误.我已经看到了C#的不同解决方案,但是我使用.net
But with updating the CustomerInfo I do not get any error. I have seen different solutions for C# but I use .net
有什么主意吗?
推荐答案
您的问题与参照完整性有关.您不能删除某个表( table table_Project
中的某些记录当前正在引用的记录(从表 tbl_Customer
中)示例).除非您要更新密钥(在您的情况下为 CustomerID
),否则 UPDATE
与 DELETE
有所不同. UPDATE
修改记录,而 DELETE
删除记录.
Your problem has something to do with referential integrity. You cannot delete a record (from table tbl_Customer
) which is currently being referenced by some records in a certain table (table table_Project
for example). UPDATE
is different from DELETE
unless you are updating the key, in your case CustomerID
. UPDATE
modifies a record while DELETE
removes the record.
看看这个例子,
tbl_Customer表
CustomerID CustomerName
1 Hello
2 World
table_Project表
CustomerID ProjectName
1 Webscripting
1 Database Maintenance
您总是可以在表 tbl_customer
的记录 2
上执行所需的任何操作,因为没有引用该记录的记录.但是在记录 1
中,除非删除表 table_Project
中的两条记录,否则无法将其删除.您可以修改列 CustomerName
,但如果仍被引用,则不能修改 CustomerID
.
You can always do anything you want on record 2
of table tbl_customer
because there is no record that is referencing to it. But in record 1
, you can't delete it unless the two records from table table_Project
are deleted. You can modify column CustomerName
but not CustomerID
is if still being referenced.
这篇关于DELETE语句与REFERENCE冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!