This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Oracle/OAS and the fly likes  Why to set constraint Defferrable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark " Why to set constraint Defferrable" Watch " Why to set constraint Defferrable" New topic
Author

Why to set constraint Defferrable

Mahtab Alam
Ranch Hand

Joined: Mar 28, 2012
Posts: 222


Why to use Defferrable when we can disable the constraint and later enable it.
So what other functionality Defferable gives.

Oracle Java Programmer , Oracle SQL Expert
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

It's not the same. Disabling/enabling a constraint is a DDL operation, it means it will commit your current transaction. Therefore, you cannot disable and then re-enable a constraint all as a part of a single transaction.

Deferrable constraint, on the other hand, can be "switched off" inside a transaction and be evaluated only when the transaction commits, or when set back to immediate within the transaction. Database is therefore never seen by other sessions to be in a state that is not conform with the constraint*. This wouldn't be true in the first case.

* At least some versions of Oracle have bugs due to which a constraint that was deferred in a transaction can end up being violated after commit, when the data protected by the constraint were modified by different sessions concurrently. I've seen it myself. This decreases the utility of deferrable constraints greatly, of course.

Have you read the Database Concepts Guide, as I have suggested elsewhere? It might look like a lot of read, but it will save you the time in the long run. It's really a great introduction into Oracle (or databases in general) even for people with little prior knowledge - at least according to my own experience.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why to set constraint Defferrable
 
Similar Threads
Web.xml - ByPass security
UML Question
Security Problem
UML 486 Question
Simple and Classic tags understanding