删除级联

发布于 2024-11-30 01:05:05 字数 796 浏览 3 评论 0原文

我有一个包含外键的关系表,其中没有设置“删除级联”属性。现在我想删除一条特定的记录,但我无法做到!

当我尝试从引用的关系中删除记录时,出现错误“删除语句与外键约束冲突。”

当我尝试从引用关系中删除记录时,它给出了相同的错误。

即使我现在也无法更改数据库架构。有出路吗?

更新: 关系模式

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

謌踐踏愛綪 2024-12-07 01:05:05

您可能正在使用 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文