1 建表SQL> create table t_p (id number, name varchar2(30));Table createdSQL> alter table t_p add primary key (id);Table alteredSQL> create table t_c (id number, fid number, name varchar2(30));Table createdSQL> alter table t_c add constraint fk_t_c foreign key(fid) references t_p(id);Table alteredSQL> insert into t_p values (1, "a");1 row insertedSQL> insert into t_p values (2, "b");1 row insertedSQL> insert into t_c values (1, 1, "a");1 row insertedSQL> commit;Commit complete
2 on delete no actionSQL> delete t_p where id = 1;delete t_p where id = 1ORA-02292: 违反完整约束条件 (MYHR.FK_T_C) - 已找到子记录SQL> UPDATE T_P SET ID = 3 WHERE ID = 1;UPDATE T_P SET ID = 3 WHERE ID = 1ORA-02292: 违反完整约束条件 (MYHR.FK_T_C) - 已找到子记录
3 on delete set nullSQL> alter table t_c drop constraint fk_t_c;Table alteredSQL> alter table t_c add constraint fk_t_c foreign key (fid) references t_p (id) on delete set null;Table alteredSQL> delete t_p where id = 1;1 row deletedSQL> commit;Commit completeSQL> select * from t_p; ID NAME---------- ------------------------------ 2 b SQL> select * from t_c; ID FID NAME---------- ---------- ------------------------------ 1 a方格内为空
4 on delete cascadeSQL> alter table t_c drop constraint fk_t_c;Table alteredSQL> alter table t_c add constraint fk_t_c foreign key (fid) references t_p (id) on delete cascade;Table alteredSQL> delete t_p where id = 1;1 row deletedSQL> select * from t_p; ID NAME---------- ------------------------------ 2 bSQL> select * from t_c; ID FID NAME---------- ---------- ------------------------------ 记录被级联删除Oracle约束enable validate时的数据检查Oracle可延迟约束Deferable的使用相关资讯 Oracle数据库 Oracle入门教程 oracle数据库教程
- Oracle数据库全球化 (03月01日)
- Oracle数据库日期过滤方法性能比较 (02/02/2015 13:20:26)
- Oracle数据库安装中端口被占用问题 (10/29/2014 07:42:24)
| - 在CentOS 6.6上搭建C++运行环境并 (10/10/2015 19:44:40)
- Oracle数据库无法使用localhost和 (11/14/2014 16:39:10)
- 使用SQLT来构建Oracle测试用例 (08/28/2014 06:17:41)
|
本文评论 查看全部评论 (0)