Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why to set constraint Defferrable

 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why to use Defferrable when we can disable the constraint and later enable it.
So what other functionality Defferable gives.
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic