Solved

Retrieve a dropped constraint

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

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

773 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