Oracle:关闭开启所有外键

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

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

1.关闭所有外键

SET SERVEROUTPUT ON SIZE 50000
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 50000
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;

转载于:https://my.oschina.net/hengbao666/blog/1789445

你可能感兴趣的:(Oracle:关闭开启所有外键)