delete语句怎么用
语法:DELETE [table.*] FROM table WHERE criteria
说明:table参数用于指定从其中删除记录的表的名称。
criteria参数为一个表达式,用于指定哪些记录应该被删除的表达式。
可以使用 Execute 方法与一个 DROP 语句从数据库中放弃整个表。不过,若用这种方法删除表,将会失去表的结构。不同的是当使用 DELETE,只有数据会被删除;表的结构以及表的所有属性仍然保留,例如字段属性及索引。
扩展资料:
如果需要在delete的时候,按照条件删除记录,那么可能会用到子查询。
但是如下情况:
delete from student where id = (select max(id) from student);
[Err] 1093 - You can't specify target table 'student' for update in FROM clause
解决办法是:给 from 子句中的结果集起别名。
delete from student where id = (select n.max_id from (select max(id) as max_id from student) as n);
这个方法对in还是适用的
delete from student where id in (select id from student where id > 30);
[Err] 1093 - You can't specify target table 'student' for update in FROM clause
解决方法同上:
delete from student where id in (select n.id from (select id from student where id > 30) as n)
参考资料来源:百度百科-DELETE语句