Drop table cascade constraints
SQL> create table t (id number,name varchar2(20));
Table created.
SQL> create table t1 (id number,sal number);
Table created.
SQL> alter table t add constraint t_pk primary key (id);
Table altered.
SQL> alter table t1 add constraint t_fk foreign key (id) references t (id);
Table altered.
SQL> insert into t values (1,#39;JACK');
1 row created.
SQL> insert into t values (2,#39;MARY');
1 row created.
SQL> COMMIT;
Commit complete.
SQL> insert into t1 values (1,1000);
1 row created.
SQL> insert into t1 values (2,1500);
1 row created.
SQL> commit;
SQL> insert into t1 values (3,200);
insert into t1 values (3,200)
*
ERROR at line 1:
ORA-02291: integrity constraint (SYS.T_FK) violated - parent key not found
(違反了constraint,員工基本資料表根本沒有3號這個員工,何來的銷售紀錄。)
SQL> drop table t;
drop table t
*
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys
(違反了constraint,員工銷售表t1有參照到table t,這個reference relation不允許你drop table t)
SQL> drop table t cascade constraints;
Table dropped.
SQL> select * from t1;
ID SAL
---------- ----------
1 1000
2 1500
SQL> select CONSTRAINT_NAME,TABLE_NAME from dba_constraints where wner = #39;SYS' and TABLE_NAME = 'T1'
no rows selected
SQL>
我們可以發現利用Drop table cascade constraints可以以刪除關聯table t的constraint來達成你drop table t的目的,原來屬於t1的foreign key constraint已經跟隨著被刪除掉了,但是,儲存在table t1的資料可不會被刪除,也就是說Drop table cascade constraints 是不影響到儲存於objec裡的row data。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/35489/viewspace-670044/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- DROP TABLE ** CASCADE CONSTRAINTS PURGEAI
- 外來鍵約束drop table cascade constraintsAI
- 主子表drop table constraints cascade的測試AI
- Oracle中drop user和drop user cascade的區別Oracle
- drop table和truncate table的區別
- flashback drop/query/table/database/archiveDatabaseHive
- How To Efficiently Drop A Table With Many Extents
- oracle 誤刪表 drop tableOracle
- drop apply INSTANTIATION for one tableAPP
- audit drop table為什麼不行
- [doc]How To Efficiently Drop A Table With Many Extents
- Oracle OCP 1Z0-053 Q85(DROP USER CASCADE)Oracle
- Oracle10g 回收站及徹底刪除table : drop table xx purge 以及drop flashOracle
- 深入解析 oracle drop table內部原理Oracle
- MySQL資料災難挽救之drop tableMySql
- Drop Table Fails With ORA-600 [15264]AI
- MySQL 5.6 drop database時,table metadata lock等待MySqlDatabase
- [重慶思莊每日技術分享]-執行DROP USER ... CASCADE操作刪除很慢
- Truncate table 詳解及與delete,drop 的區別delete
- Truncate table詳解及與delete,drop的區別delete
- 資料庫審計(create/alter/drop table、user、tablespace)資料庫
- v$lock之alter table drop column與alter table set unused column區別系列五
- oracle多使用者使用同一個表空間_drop user cascade的影響Oracle
- oracle drop table purge無備份bbed恢復(1/3)Oracle
- oracle drop table purge無備份bbed恢復(2/3)Oracle
- oracle drop table purge無備份bbed恢復(3/3)Oracle
- 執行drop table base purge出現ora_00604
- Drop Table Fails With ORA-600 [15264] [ID 338953.1]AI
- MySQL DROP TABLE刪除表報錯'ERROR 1051 (42S02): Unknown table'MySqlError
- 【TABLESPACE】使用 CASCADE CONSTRAINTS選項刪除表空間時對資料庫物件影響的探查AI資料庫物件
- Oracle10g 回收站及徹底刪除table : drop table xx purge 以及flashbackOracle
- 閃回之 回收站、Flashback Drop (table、index、trigger等)Index
- oracle10g_alter table shrink space_compact_cascade回收空間測試(一)Oracle
- Cascade屬性
- ORACLE CASCADE DATAGUARDOracle
- 直接登入資料庫使用drop table tablename;會是什麼情況?資料庫
- [20181203]drop table後如何獲得表結構.txt
- D. Matrix Cascade