--报错:有外键存在,子记录被发现

--删除实验表2中的外键约束
-- Drop primary, unique and foreign key constraints
altertable FK_TEST
dropconstraint FK_PK_TEST;
--再次删除实验表1中的数据,成功删除
deletefrom pk_test;
commit;
--查询实验表1中的数据为空
select *from pk_test;

小结:
这说明当存在外键时,是无法直接对父表做删除数据操作的。解决这个,可以采用将约束去掉,或连同SALES表中的数据一并删除。
?
170、DELETE
170. Which two statements are true regarding the DELETE and TRUNCATE commands? (Choose two.)
A. DELETE can be used to remove only rows from only one table at a time.
B. DELETE can be used to remove only rows from multiple tables at a time.
C. DELETE can be used only on a table that is a parent of a referential integrity constraint.
D. DELETE can be used to remove data from specific columns as well as complete rows.
E. DELETE and TRUNCATE can be used on a table that is a parent of a referential integrity constraint having ON DELETE rule.
?
答案:AE
对于完整性约束的父表,需要在建表时使用ON DELETE CASCADE或ON DELETE CASCAD SET NULL条件子句,才可以使用delete或truncate对完整性约束的父表进行删除操作。
关于 ON DELETE CASCADE或ON DELETE CASCAD SET NULL这两个参数,在网上查看其它资料是这么解释的:
ON DELETE CASCADE(当删除父表数据时,子表数据也一起删除)
ON DELETE CASCAD SET NULL(当删除父表数据时,子表相关的列设置为NULL)
可以在SQL Language Reference里的Constraints部分查找到ON DELETE子句。
?
单词释义:
regarding:关于
referential:指示的,用作参考的
integrity:完整
constraint:约束