Monday, October 6, 2008

oracle 10g drop primary key cascade does not drop index

Bug or feature?

First the theory.
If you have a table, that has a primary key, in the background there is a index created for the primary key.
If you are from the oracle 9 and previous realm then you would be thinking, if i drop the primary key and say cascade, then the index too would be dropped. And this is true as well.

Not so for Oracle 10g.
And this is a feature of 10G not a bug!! ;)

So what is the behaviour!

With 10g the index does not get dropped by default syntax.
Shut uo and show me the code! ;(

With Oracle 9 and previous
ALTER TABLE my_table DROP PRIMARY KEY CASCADE;

This will drop the primary key along with the index.

What is the new syntax?

If you use the syntax above the index does not get dropped.

To drop the index you need to do this.
ALTER TABLE my_table DROP PRIMARY KEY CASCADE DROP INDEX;


Whatz the other side?

The otherside is

ALTER TABLE my_table DROP PRIMARY KEY CASCADE KEEP INDEX;

Where did I find helpful link!

Here, http://www.orafaq.com/forum/t/59807/0/

No comments: