Problem solve Get help with specific problems with your technologies, process and projects.

Enable all disabled constraints

Here's an Oracle script that enables all disabled constraints.

The following creates the script enable_cons.sql that enables all disabled constraints. It must be run by Oracle...

user SYSTEM. It has been tested on Oracle 7.3 onwards.

set pages 0
set lines 132
set timing off
spool enable_cons.sql
select 'alter table',owner||'.'||table_name,'enable constraint',CONSTRAINT_NAME,';'
from all_constraints
where status='DISABLED';
spool off

Reader Feedback

Paul B. writes: This script has an error in the select statement. It should be:

select 'alter table '||owner||'.'||table_name||' enable constraint '||CONSTRAINT_NAME||';'
from all_constraints
where status='DISABLED';

Martin C. writes: This process could be costly as it will create the indexes from the constraints in the default tablespace of the owner of the table.

For More Information

  • What do you think about this tip? E-mail the editor at [email protected] with your feedback.
  • The Best Oracle Web Links: tips, tutorials, scripts, and more.
  • Have an Oracle tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize--submit your tip today!
  • Ask your technical Oracle questions--or help out your peers by answering them--in our live discussion forums.
  • Check out our Ask the Experts feature: Our SQL, database design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.

Dig Deeper on Oracle and SQL