Enable and disable the check constraints for table in Oracle

Enable and disable all check constraints for table in Oracle

Enable the check constraints for all tables in Schema

SET SERVEROUTPUT ON
DECLARE
   v_owner VARCHAR(30) := UPPER('&2');
   v_table_name VARCHAR(30) := UPPER('&1');
BEGIN
  FOR c in (select constraint_name,table_name,owner from all_constraints where constraint_type='C' and owner = v_owner )
loop
   EXECUTE IMMEDIATE 'ALTER TABLE '||v_owner||'.'||c.table_name||' enable CONSTRAINT '||c.constraint_name||'''';
END LOOP;
END;
/

Disable the Check constraint in all tables of schema

SET SERVEROUTPUT ON
DECLARE
   v_owner VARCHAR(30) := UPPER('&2');
   v_table_name VARCHAR(30) := UPPER('&1');
BEGIN
  FOR c in (select constraint_name,table_name,owner from all_constraints where constraint_type='C' and owner = v_owner )
loop
   EXECUTE IMMEDIATE 'ALTER TABLE '||v_owner||'.'||c.table_name||' DISABLE CONSTRAINT '||c.constraint_name||'''';
END LOOP;
END;
/

Enable and disable the check constraint

select constraint_name, table_name, owner from all_constraints where constraint_type='C' and owner = '' and table_name = '';


-- Enable 
ALTER table table_name enable constraint constraint_name;

--Disable 
ATLER table table_name disable constraint constraint_name;
This entry was posted in Oracle on by .
Unknown's avatar

About SandeepSingh

Hi, I am working in IT industry with having more than 15 year of experience, worked as an Oracle DBA with a Company and handling different databases like Oracle, SQL Server , DB2 etc Worked as a Development and Database Administrator.

Leave a Reply