sql查询删除命令 [英] sql query for Delete Command

查看:85
本文介绍了sql查询删除命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果两个表之间存在关系,那么如何从主表中删除一行(相关记录也应从相关表中删除).如何编写sql查询...?

解决方案

在CASCADE选项处于启用状态的情况下,可以使用对另一个表具有外键.
请参见此处 [删除级联上 [ 删除 FROM child_table 位置 parentID = @ ID 删除 FROM ID = @ ID


If There is a relation between two tables then how to delete a row from main table(related records also should be deleted from related table).How can we write sql query...?

You can use have a foreign key to the other table with the CASCADE option on.
See
here[^] to read more about this.


First of all if this is a requirement then you should have the the tables configure to support it, on delete cascade[^]

Otherwise

DELETE FROM child_table
WHERE parentID = @ID

DELETE FROM table
WHER id = @ID


这篇关于sql查询删除命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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