删除级联
我有一个包含外键的关系表,其中没有设置“删除级联”属性。现在我想删除一条特定的记录,但我无法做到!
当我尝试从引用的关系中删除记录时,出现错误“删除语句与外键约束冲突。”
当我尝试从引用关系中删除记录时,它给出了相同的错误。
即使我现在也无法更改数据库架构。有出路吗?
更新: 关系模式
Customer(c_id,c_name);
Products(p_id,p_name,p_cost);
purchases(p_id references Products,c_id references Customr);
我想从 purchases
关系中删除一个元组。
更新:删除语句
该表已包含以下数据:
c_id p_id
1 4
1 3
1 2
1 1
2 3
1 4(注意重复的元组)
现在我想删除此行上方的记录。即重复记录。 我只需右键单击管理工作室中表视图中显示的元组,然后按删除键。它给出了错误。
更新
我用过
delete from Purchases where c_id=1 and p_id=4
它工作得很好!
最初,我通过在表视图中选择记录并按删除键来删除。现在它起作用了。谁能解释一下有什么区别吗?
I have a relational table containing a foreign key in which there is no "on delete cascade" property set. Now I wanna delete a particular record but I am unable to do it!
When I try to delete a record from the referenced relation, It gives error "The delete statement conflicted with the foreign key constraint."
When I try to delete a record from the referencing relation, It gives the same error.
Even I cannot change the database schema now. Any way out?
Update:
The relational Schema
Customer(c_id,c_name);
Products(p_id,p_name,p_cost);
purchases(p_id references Products,c_id references Customr);
I wanna delete a tuple from the purchases
relation.
Update : The delete statement
The table already contains the following data :
c_id p_id
1 4
1 3
1 2
1 1
2 3
1 4(Notice duplicate tuple)
Now I wanna delete the record just above this line. i.e. the duplicate record.
I just right-clicked on the tuple shown in the table-view in the management studio and hit the delete key. It gived error.
UPDATE
I used
delete from Purchases where c_id=1 and p_id=4
It worked All Fine!!!
Initially I used to delete by selecting the record in the table-view and pressing the delete key. Now it worked. Can anyone Please explain me whatwas the difference?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能正在使用 SQL Server Management Studio 中的“编辑前 X 条记录”界面来删除该记录。此功能要求您在表上定义主键,因为它需要能够唯一标识您尝试删除的行。它不能直接从表中删除行,它所做的只是在后台为您构造 SQL。您在表上定义了主键吗?
You were probably using the Edit top X records interface in SQL Server Management Studio to delete the record. This functionality requires you to have a primary key defined on the table, since it needs to be able to uniquely identify the row you are trying to delete. It cannot delete the row from the table directly, all it does is construct the SQL in the background for you. Do you have a Primary Key defined on the table?