Disable all table constraints in Oracle

后端 未结 11 971
耶瑟儿~
耶瑟儿~ 2020-11-28 18:35

How can I disable all table constrains in Oracle with a single command? This can be either for a single table, a list of tables, or for all tables.

11条回答
  •  无人及你
    2020-11-28 18:53

    Use following cursor to disable all constraint.. And alter query for enable constraints...

    DECLARE
    
    cursor r1 is select * from user_constraints;
    cursor r2 is select * from user_tables;
    
    BEGIN
      FOR c1 IN r1
      loop
        for c2 in r2
        loop
           if c1.table_name = c2.table_name and c1.status = 'ENABLED' THEN
            dbms_utility.exec_ddl_statement('alter table ' || c1.owner || '.' || c1.table_name || ' disable constraint ' || c1.constraint_name);
           end if;
        end loop;
      END LOOP;
    END;
    /
    

提交回复
热议问题