林大鹏 2020-05-12
单个表的删除:
DELETE FROM tableName WHERE columnName = value;
删除表内的所有行:
即:保留表的结构、属性、索引
DELETE FROM tablename;
DELETE * FROM tablename;
删除同一张表内的所有内容(删除数据、表结构)
TRUNCATE customer;
无法报告删除了几行,且只能用于单一表
多表连接删除:
DELETE orders,items FROM orders,items
WHERE orders.userid = items.userid
AND orders.orderid = items.orderid
AND orders.date<”2000/03/01”;
需要删除的表的名称列在DELETE之后,连接条件所用的表列在FROM之后
假设删除BV地区的所有葡萄酒场,但不删除地名
DELETE winery FROM region,winery
WHERE winery.regionid = region.regionid
AND region.regionname = ‘BV’;
查询只影响winery表,但同时利用winery,region找出需要删除的记录
使用高级连接查询
DELETE orders,items FROM orders
INNER JOIN otems ON orders.orderid = items.orderid
AND orders.userid = items.userid
WHERE orders.date<”2000/03/01”;
也可在DELETE语句中使用嵌套查询(内部查询不可引用删除的数据)、GROUP BY、HAVING;
也可在单一表查询中使用ORDER BY,单数除非与LIMIT连用删除部分数据行,否则并无太大意义。
加quick修饰符,可快速删除索引项,加速大量或者频繁的删除操作
DELETE QUICK FROM customer WHERE userid<10;
只可用于类型为MyISAM的表
清理MyISAM的表
OPTIMIZE TABLE customer;
来自:https://blog.csdn.net/u013043762/article/details/80238372