Oracle:关闭开启所有外键

请使用sqlplus或者plsql的命令窗口执行语句,如果是plsql,请使用命令窗口,在末尾敲入/,然后回车即可。

1.关闭所有外键

SET SERVEROUTPUT ON SIZE 500000
BEGIN
for c in (select 'ALTER TABLE '||TABLE_NAME||' DISABLE CONSTRAINT '||constraint_name||' ' as v_sql from user_constraints where CONSTRAINT_TYPE='R' or CONSTRAINT_TYPE='C') loop
DBMS_OUTPUT.PUT_LINE(C.V_SQL);
begin
EXECUTE IMMEDIATE c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop;
end;

2.开启所有外键

SET SERVEROUTPUT ON SIZE 500000
begin
for c in (select 'ALTER TABLE '||TABLE_NAME||' ENABLE CONSTRAINT '||constraint_name||' ' as v_sql from user_constraints where CONSTRAINT_TYPE='R' or CONSTRAINT_TYPE='C') loop
DBMS_OUTPUT.PUT_LINE(C.V_SQL);
begin
EXECUTE IMMEDIATE c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop;
end;

 

posted @ 2019-10-17 16:02  怡安  阅读(875)  评论(0编辑  收藏  举报