开发者

How to delete records from Child table and Parent table in a single query?

I have a master table and a details table. On delete cascade is not specified.

I want delete child开发者_JS百科 record as well as master record in a single query.

Suppose I want to delete EmployeeDetails and Employee record where EmpID=20 using a single query.

Is it possible?

Please help.


you cannot do it in a single query unless you have cascade delete turned on or you have a trigger on the PK table that will delete the FK table rows for that relationship


There is no construct in SQL that allows you to delete from two tables in a singe command. You can do that in a single "batch" or in a transaction (which will be preferable).


you could add a trigger on the child table to delete any other children and then the parent. This is not "technically" a single statement, but your application only needs to issue a single DELETE and it is all done for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜