级联删除查询

编程入门 行业动态 更新时间:2024-10-23 01:54:24
本文介绍了级联删除查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有三个桌子. 产品,公司,员工

I have three tables. Product, Company, Employee

ProductId是公司的forgin键 并且Company表的CompanyId是Employee的前瞻键

ProductId of Product table is foregin key for Company and CompanyId of Company table is foregin key for Employee

因此,从Product表中删除ProductId时,其他表中的所有相关记录都应删除.但是我不能碰模式(不能使用alter table).在这种情况下,我应该如何编写查询.

So on deleting ProductId from Product table, all the related records in other tables should delete. But I can't touch schema(can't use alter table). How should I write the query in that case..

推荐答案

如果您无法添加传播删除操作的约束,则必须自己编写所有必需的删除操作:

If you can't add constraints that propagates the delete, you have to write all the necessary deletes yourself:

delete employee where companyid in (select companyid from company c where productid = xxx); delete company where productid=xxx; delete product where productid=xxx;

更多推荐

级联删除查询

本文发布于:2023-10-16 05:45:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1496670.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:级联

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!