在轉(zhuǎn)移數(shù)據(jù)庫,進行數(shù)據(jù)導入的時候,遇到一件麻煩事,就是表間外鍵約束的存在,導致insert頻頻報錯,批量執(zhí)行sql語句又是順序執(zhí)行,沒辦法我只好手動輸入。
然后輸入到一半靈光一閃,為什么不先把外鍵約束全部禁用先呢?
于是我百度到以下資料:
oracle 刪除(所有)約束 禁用(所有)約束 啟用(所有)約束
執(zhí)行以下sql生成的語句即可
1刪除所有外鍵約束
select 'alter table '||table_name||' drop constraint '||constraint_name||';' from user_constraints where constraint_type='R'
2禁用所有外鍵約束
select 'alter table '||table_name||' disable constraint '||constraint_name||';' from user_constraints where constraint_type='R'
3啟用所有外鍵約束
select 'alter table '||table_name||' enable constraint '||constraint_name||';' from user_constraints where constraint_type='R'
在SQL Plus中輸入語句后,生成了很多語句,這些語句其實是沒執(zhí)行的,復制下來執(zhí)行一遍就好了。
然后我們可以根據(jù)這個腳本一樣的sql語句進行拼裝,得到我們需要的語句:
禁用所有外鍵約束:
select 'ALTER TABLE "QIANHAI"."'||table_name||'" MODIFY CONSTRAINT "'||constraint_name||'" DISABLE;' from user_constraints where constraint_type='R'
啟用所有外鍵約束:
select 'ALTER TABLE "QIANHAI"."'||table_name||'" MODIFY CONSTRAINT "'||constraint_name||'" ENABLE;' from user_constraints where constraint_type='R';
關(guān)于Oracle批量執(zhí)行sql語句之禁用所有表的外鍵的相關(guān)內(nèi)容,就給大家介紹這么多,后續(xù)還會持續(xù)更新,感興趣的朋友請繼續(xù)關(guān)注腳本之家網(wǎng)站,謝謝!
您可能感興趣的文章:- Oracle批量插入數(shù)據(jù)的三種方式【推薦】
- C# Oracle批量插入數(shù)據(jù)進度條的實現(xiàn)代碼
- Oracle + Mybatis實現(xiàn)批量插入、更新和刪除示例代碼
- MyBatis批量插入數(shù)據(jù)到Oracle數(shù)據(jù)庫中的兩種方式(實例代碼)
- Oracle兩張表關(guān)聯(lián)批量更新其中一張表的數(shù)據(jù)
- Oracle批量查詢、刪除、更新使用BULK COLLECT提高效率
- mybatis執(zhí)行批量更新batch update 的方法(oracle,mysql兩種)
- Oracle批量導入文本文件快速的方法(sqlldr實現(xiàn))
- Oracle+Mybatis的foreach insert批量插入報錯的快速解決辦法
- Java實現(xiàn)mybatis批量插入數(shù)據(jù)到Oracle
- oracle+mybatis 使用動態(tài)Sql當插入字段不確定的情況下實現(xiàn)批量insert
- Oracle 高速批量數(shù)據(jù)加載工具sql*loader使用說明
- Oracle數(shù)據(jù)庫更新大批量數(shù)據(jù)案例