本文介绍了级联删除查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有三个桌子. 产品,公司,员工
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;更多推荐
级联删除查询
发布评论