数据删除delete命令:删除满足指定条件的元祖
Delete from 表名 [where 条件表达式];
如果where条件省略,则删除所有数据;
示例:
1 删除student_course表中所有数据
DELETE
FROM
student_course;
2 删除1120120005号学生所选的所有课程
DELETE
FROM
student_course
WHERE
student_id = ‘1120120005’;
3
删除宇航学院的所有学生
DELETE
FROM
student
WHERE
dept_id IN (
SELECT
dept_id
FROM
dept
WHERE
dept_name = ‘宇航学院’
);
4
删除有一门课程不及格的所有同学
DELETE
FROM
student
WHERE
student_id IN (
SELECT
student_id
FROM
student_course
WHERE
score < 60
GROUP BY
student_id
HAVING
count(*) >= 1
);
当删除数据时,
DBMS
会检查用户定义的完整性约束,若不符合完整性约束条件将不会执行删除操作。