Wednesday , December 25 2024

Deferrable Primary Key In Oracle

In today’s article, we may want it to come into play later when defining the Primary Key. For this, we will learn how to use “DEFERRABLE INITIALLY DEFERRED”.

But this does not mean that I will be able to add inconsistent data to the table. Yes, it can be added, but it will not be made permanent.

The reason is that in the worst case scenario, the primary key will come into play after the session is closed and will act in this way to eliminate the inconsistency.

Let’s create a new table.

Then I will add a primary key to the cust_id field in this table, but I won’t put it into effect right away.

Then I try to insert things into the table that violate the primary key.

It will do the first insert successfully.

It will do the second insert successfully.

When I press Commit, I get an error like the one below.

The disabled constraint is enabled as follows.

Afterwards, when I try new inserts, if it finds any contradictions, it will give an error at the insertion stage.

Commit;

Loading

About Onur ARDAHANLI

Leave a Reply

Your email address will not be published. Required fields are marked *