学习内容:
SQL第15课:删除行
表:Movies
Exercise 15 — Tasks
- This database is getting too big, lets remove all movies that were released before 2005.
- Andrew Stanton has also left the studio, so please remove all movies directed by him.
需要掌握的SQL语句
删除带条件的语句
DELETE FROM mytable
WHERE condition;
注意:与UPDATE上一课中的语句一样,建议您SELECT首先在查询中运行约束,以确保删除正确的行。没有适当的备份或测试数据库,很容易不可撤销地删除数据,因此请始终阅读您的DELETE语句两次并执行一次。
输出结果
1.delete FROM movies
where year<2005
前置步骤,先用select查找出需要删除的行
select title,year
from movies
where year<2005
2.delete from movies
where director="Andrew Stanton"
总结:
单词delete不要书写错;凡是默认的函数或者语句,SQL语句输入时会变化颜色~