单个SQL查询删除两个表中的记录

时间:2016-02-15 09:17:18

标签: mysql vb.net

这些是我的表格:

tbl_student (studID,Firstname) 

我的专注是 priid

finger_template(Detail_ID,FingerprintMask)

我想删除tbl_studentfinger_template中的记录。这是我的查询:

  

command = New MySqlCommand("DELETE from tbl_student where studid='" & priid & "'", connection, transaction)

希望有人会帮助

1 个答案:

答案 0 :(得分:1)

表:tbl_student

+-------------+-----------+
| studID (PK) | Firstname |
+-------------+-----------+
| **000001**  | John      |
+-------------+-----------+

表:finger_template

+----------------+-----------------+-------------+
| Detail_ID (PK) | FingerprintMask | studID (FK) |
+----------------+-----------------+-------------+
| 000001         | SampleMask      | **000001**  |
+----------------+-----------------+-------------+

如果tbl_student studID PK链接到finger_template stuID FK 你只需删除studID PK,FK也会被删除DELETE FROM tbl_student WHERE studID=000001

相关问题