ITPub博客

首页 > 数据库 > MySQL > MySQL 多表关联删除

MySQL 多表关联删除

原创 MySQL 作者:feelpurple 时间:2016-11-18 18:08:51 0 删除 编辑
在MySQL中,删除关联的多张表,可以使用下面SQL
mysql> delete e, d from emp e inner join dept d on e.deptno=d.deptno where e.deptno=10;
Query OK, 4 rows affected (0.01 sec)


delete后面的e, d是表的缩写名

执行成功后,两张表中的对应数据会被删除
mysql> select * from dept;
+--------+------------+---------+
| deptno | dname      | loc     |
+--------+------------+---------+
|     20 | RESEARCH   | DALLAS  |
|     30 | SALES      | CHICAGO |
|     40 | OPERATIONS | BOSTON  |
|     50 | Research   | BeiJing |
+--------+------------+---------+
4 rows in set (0.00 sec)

mysql> select * from emp where deptno=10;
Empty set (0.00 sec)

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26506993/viewspace-2128714/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-08-01

  • 博文量
    404
  • 访问量
    1673950