Solved

Retrieve a dropped constraint

Posted on 2014-07-23
4
225 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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to recover a database from a user managed backup

920 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

18 Experts available now in Live!

Get 1:1 Help Now