转载自:http://blog.sina.com.cn/s/blog_4c197d420101aeqr.html
DELETE是一个蛮慎重的SQL操作,一般来说这样删除操作都需要谨慎小心,以免造成不必要的损失。
DELETE有下面这几种情况:
Ø
Ø
Ø
Ø
简单地说就是delete语句是无法进行多表删除数据操作,不过可以通过建立级联删除,在两个表之间建立级联删除关系,来实现删除一个表的数据时,同时删除另一个表中相关的数据。
举例说明:
1)
DELETE MV
FROM MV,Track
WHERE Track.trkid=MV.mvid
等同于
DELETE FROM MV
USING MV,Track
WHERE Track.trkid=MV.mvid
2)
DELETE MV
FROM MV
LEFT JOIN Track
ON MV.mvid=Track.trkid
WHERE Track.trkid IS NULL
等同于
DELETE FROM MV
USING MV
LEFT JOIN Track
ON MV.mvid=Track.trkid
WHERE Track.trkid IS NULL
3)
DELETE MV,Track
FROM MV
LEFT JOIN Track
ON MV.mvid=Track.trkid
WHERE MV.mvid=1
用别名的方式:
DELETE t1,t2
FROM MV t1
LEFT JOIN Track t2
ON t1.mvid=t2.trkid
WHERE t1.mvid=2
※
delete MV,Track
from MV as t1
left join Track as t2
on t1.mvid=t2.trkid
where t1.mvid=5
***********************
DELETE t1,t2
FROM MV t1
LEFT JOIN Track t2
ON t1.mvid=t2.trkid
WHERE MV.mvid=2
so 如果使用了别名的方式,那么上下一致都用别名。