drop tablespace cascade constraints 后如果其它tablespace 中的表存在对被删除tablespace中表的外键参照,如果建立外键约束的时候指定on delete cascade,那么这些子表的记录会如何呢?
[@more@]建立表空间1:
SQL> create tablespace test1 datafile '/oradata/test/test101.dbf' size 20M autoextend off;
Tablespace created
建立表空间2:
SQL> create tablespace test2 datafile '/oradata/test/test201.dbf' size 20M autoextend off;
Tablespace created
SQL>
SQL>
SQL>
在表空间1上建立表1:
SQL> create table t1 (a int,b int) tablespace test1;
Table created
在表空间2上建立表2:
SQL> create table t2 (a int) tablespace test2;
Table created
在表1上添加主键:
SQL> alter table t1 add primary key(a);
Table altered
在表2上添加对表1的外键约束,级联删除
SQL> alter table t2 add constraint f1 foreign key(a) references t1(a) on delete cascade;
Table altered
在表1中添加记录:
SQL> insert into t1 values(0,0);
1 row inserted
SQL> insert into t1 values(1,1);
1 row inserted
SQL> insert into t1 values(2,2);
1 row inserted
SQL> commit;
Commit complete
在表2中添加记录:
SQL> insert into t2 values(0);
1 row inserted
SQL> insert into t2 values(1);
1 row inserted
SQL> insert into t2 values(2);
1 row inserted
SQL> insert into t2 values(3);
insert into t2 values(3)
ORA-02291: 违反完整约束条件 (SYS.F1) - 未找到父项关键字
CASCADE CONSTRAINTS 方式删除表空间1:
SQL> drop tablespace test1 including contents and datafiles cascade constraints;
Tablespace dropped
查询表2的信息:
SQL> select * from t2;
A
---------------------------------------
0
1
2
以上实验表明:在没有显示触发表1上的delete操作的时候,表2的记录不会被级联删除。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7437037/viewspace-912966/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/7437037/viewspace-912966/