Solved

Retrieve a dropped constraint

Posted on 2014-07-23
4
223 Views
Last Modified: 2014-10-03
A constraint with a system generated name (SYS_CXXXXXXX) was accidentally dropped. Is there a way to add it back. The script for the constraint is not saved and I am not even sure on what table the constraint was applied so that I could do a comparison with the datamodel

Thanks,
0
Comment
Question by:gs79
  • 2
4 Comments
 
LVL 34

Accepted Solution

by:
johnsone earned 250 total points
ID: 40216486
The only way I can think of that you might be able to retrieve it is with LogMiner.  You would have to have archive log mode turned on and know the timeframe when the drop occurred so that you could grab the correct archive(s).  It should give you the command to put back the constraint.

The documentation for LogMiner is here:

http://docs.oracle.com/cd/E11882_01/server.112/e22490/logminer.htm#SUTIL019
0
 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 125 total points
ID: 40216539
You might also look at restoring a backup to a different server and see what it was.
0
 
LVL 29

Assisted Solution

by:MikeOM_DBA
MikeOM_DBA earned 125 total points
ID: 40219596
Constraints like "SYS_CXXXXXXX" are check constraints (99% of them "NOT NULL" constraints).
If you have a test or qa instance you could compare the schema's to production.
;)
0
 
LVL 34

Assisted Solution

by:johnsone
johnsone earned 250 total points
ID: 40219752
They are not necessarily check constraints.  They can be any kind of unnamed constraint.  As long as you create it without a name, it will get a SYS_C prefix.

Take for example these 2 statements:

CREATE TABLE t 
  ( 
     x NUMBER PRIMARY KEY 
  ); 

CREATE TABLE u 
  ( 
     x NUMBER, 
     y NUMBER PRIMARY KEY, 
     FOREIGN KEY (x) REFERENCES t(x) 
  ); 

Open in new window


That will create 2 primary keys and one referential integrity constraint.  All of them will be prefixed with SYS_C.  At least they all were in the 11gR2 system I just ran those statements on.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now