Enable and Disable all constraints in Oracle

Enable and Disable all constraints in Oracle

Check the constraint present on table and owner

col type format a10
col cons_name format a24
COL TABLE_NAME FOR A25
select decode(constraint_type,
'C', 'Check',
'O', 'R/O View',
'P', 'Primary',
'R', 'Foreign',
'U', 'Unique',
'V', 'Check view') type
, constraint_name cons_name
, TABLE_NAME
from dba_constraints
where table_name='EMP'
order by 1;

Disable the cascade constraints

select 'alter table '||owner||'.'||table_name|| ' disable constraint '||constraint_name||';' from all_constraints where delete_rule = 'CASCADE' and owner = 'HR';

 
Enable the constraints

select 'alter table '||owner||'.'||table_name|| ' enable constraint '||constraint_name||';' from all_constraints where owner = 'HR';

Disable all the constraints

select 'alter table '||owner||'.'||table_name|| ' disable constraint '||constraint_name||';' from all_constraints where owner = 'HR';

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.