mysql多表刪除執行個體

來源:互聯網
上載者:User

標籤:mysql   sql   多表刪除   

mysql多表刪除


刪除某學生基本資料的同時,刪除該學生的所有成績

mysql> select * from stu_inf;+----+----------+--------+-------+-------+--------+| id | stu_xh   | stu_xm | xb_id | xy_id | stu_bj |+----+----------+--------+-------+-------+--------+|  1 | 07150101 | 小明   |     1 |     1 | 1504   ||  2 | 07150240 | 謝育政 |     1 |     2 | 1502   ||  3 | 12341231 | 猴子   |     1 |     2 | 1515   ||  4 | 01591261 | 大大   |     1 |     3 | 1515   ||  5 | 07160202 | 小紅   |     2 |     4 | 1602   ||  6 | 07150225 | 黃河   |     1 |     3 | 1315   ||  7 | 01050001 | 華容   |     1 |     7 | 1612   ||  8 | 02050002 | 黃月英 |     2 |     8 | 1608   ||  9 | 01510003 | 歡歡   |     2 |     9 | 1601   || 10 | 05261005 | 大康   |     1 |    10 | 1304   || 13 | 0001     | xxx    |     1 |     2 | 1555   |+----+----------+--------+-------+-------+--------+11 rows in set (0.02 sec)mysql> select * from cj_inf;+-------+----------+---------+----------+| cj_id | cj_stuid | cj_kmid | cj_score |+-------+----------+---------+----------+|     1 |        3 |       1 | 87       ||     2 |        1 |       2 | 65       ||     3 |        4 |       1 | 77       ||     5 |        3 |       9 | 76       ||     7 |        1 |       1 | 90       ||    15 |       13 |       9 | 90       ||    16 |       13 |       8 | 67       ||    13 |       13 |       1 | 88       |+-------+----------+---------+----------+8 rows in set (0.02 sec)


刪除語句:

mysql> DELETE stu_inf,cj_inf from stu_inf LEFT JOIN cj_inf ON stu_inf.id=cj_inf.cj_stuid WHERE stu_inf.id=13;Query OK, 4 rows affected (0.00 sec)


執行語句後:

mysql> select * from stu_inf;+----+----------+--------+-------+-------+--------+| id | stu_xh   | stu_xm | xb_id | xy_id | stu_bj |+----+----------+--------+-------+-------+--------+|  1 | 07150101 | 小明   |     1 |     1 | 1504   ||  2 | 07150240 | 謝育政 |     1 |     2 | 1502   ||  3 | 12341231 | 猴子   |     1 |     2 | 1515   ||  4 | 01591261 | 大大   |     1 |     3 | 1515   ||  5 | 07160202 | 小紅   |     2 |     4 | 1602   ||  6 | 07150225 | 黃河   |     1 |     3 | 1315   ||  7 | 01050001 | 華容   |     1 |     7 | 1612   ||  8 | 02050002 | 黃月英 |     2 |     8 | 1608   ||  9 | 01510003 | 歡歡   |     2 |     9 | 1601   || 10 | 05261005 | 大康   |     1 |    10 | 1304   |+----+----------+--------+-------+-------+--------+10 rows in set (0.00 sec)mysql> select * from cj_inf;+-------+----------+---------+----------+| cj_id | cj_stuid | cj_kmid | cj_score |+-------+----------+---------+----------+|     1 |        3 |       1 | 87       ||     2 |        1 |       2 | 65       ||     3 |        4 |       1 | 77       ||     5 |        3 |       9 | 76       ||     7 |        1 |       1 | 90       |+-------+----------+---------+----------+5 rows in set (0.02 sec)


本文出自 “Kurol.Blog” 部落格,請務必保留此出處http://kurol.blog.51cto.com/11433546/1923998

mysql多表刪除執行個體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.