disable/enable constraints

CREATE OR REPLACE PROCEDURE sp_dat_disable_constraints
IS
BEGIN
FOR i IN (SELECT table_name, constraint_name FROM user_constraints WHERE owner=’DAT’ AND constraint_type=’R’ AND status=’ENABLED’) LOOP
EXECUTE IMMEDIATE ‘ALTER TABLE ‘ || i.TABLE_NAME || ‘ DISABLE CONSTRAINT ‘ || i.constraint_name;
END LOOP i;
END;

CREATE OR REPLACE PROCEDURE sp_dat_enable_constraints
IS
BEGIN
FOR i IN (SELECT table_name, constraint_name FROM user_constraints WHERE owner=’DAT’ AND status=’DISABLED’) LOOP
EXECUTE IMMEDIATE ‘ALTER TABLE ‘ || i.TABLE_NAME || ‘ ENABLE CONSTRAINT ‘ || i.constraint_name;
END LOOP i;
END;

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s