数据表
- r_user
id: 用户ID
name: 用户名称
- r_user_role
id: 用户角色ID
user_id: 用户ID
role_id: 角色ID
单表删除
语法:DELETE FROM table_name [WHERE Clause]
例1: 删除ID为1的用户
DELETE FROM r_user WHERE id = 1
联表删除
语法:
DELETE t1,t2,t3
FROM t1
JOIN t2 ON t1.id = t2.id
JOIN t3 ON t1.id = t3.id
[WHERE Clause]
例2: 删除ID为1的用户及关联的角色
DELETE u, ur
FROM r_user u
LEFT JOIN r_user_role ur ON ur.user_id = u.id
WHERE u.id = 1
例3: 删除ID为1的用户关联的角色
DELETE ur
FROM r_user u
LEFT JOIN r_user_role ur ON ur.user_id = u.id
WHERE u.id = 1
注意
标签:删除,用户,ID,user,联表,MYSQL,ur,id From: https://www.cnblogs.com/bluebulv/p/17325485.html
DELETE
后跟需要删除哪些表中的数据, 例2中删除用户及用户角色表中的数据, 例3中删除某用户关联的角色, 不删除用户