Solved

Retrieve a dropped constraint

Posted on 2014-07-23
4
228 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 77

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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.
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

830 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