从多个表中删除数据 [英] Delete data from multiple tables

查看:84
本文介绍了从多个表中删除数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用单个查询从多个表中删除数据.


在此先感谢.

How can we delete data from multiple tables using a single query.


Thanks in advance.

推荐答案

使用 ^ ],这样数据库将始终为您处理它.

另外,我建议使用事务可能是更好的选择,可能在存储过程内.
The best way if to use Cascaded Deletes[^], so that the database will always handle it for you.

Alternatively, I would suggest that using transactions might be a better alternative, possibly inside a stored procedure.


^ ]

您想要实现什么?
http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/3ad3be26-fc6b-4a7a-8747-ced2e0b6a4e5/[^]

What do you want to achieve?


如果表是相关的(即它们具有公共键),则可以在外键规范中使用ON DELETE CASCADE子句.从主表中删除行将导致从从属表中删除所有相关的子行.

如果这些表不相关,则必须使用多个DELETE语句.
If the tables are related (i.e., they have a common key), you can use ON DELETE CASCADE clause in the foreign key specification. Deleting rows from a master table will result in the deletion of all related child rows from the dependant tables.

If the tables are not related, you must use multiple DELETE statements.


这篇关于从多个表中删除数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆