File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 256


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 , Oracle Java Web Component Developer
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why to set constraint Defferrable