let us check the demonstration:
i will create a table with primary key:
sys@LION>CREATE TABLE ersh_tab
( emp_id number(10) not null,
emp_name varchar2(50) not null,
address varchar2(50),
CONSTRAINT emp_id_pk PRIMARY KEY (emp_id)
);
Now let us make a foreign key relationship depending on this table:
sys@LION> create table opt (id number(30),emp_mail varchar2(50),constraint opt_id_fk foreign key(id) references ersh_tab(emp_id));
Now i will try to drop the primary key constraints, which is emp_id_pk:
sys@LION> alter table ersh_tab drop constraint emp_id_pk;
alter table ersh_tab drop constraint emp_id_pk * ERROR at line 1: ORA-02273: this unique/primary key is referenced by some foreign keys
solution is :
first drop the foreign key constraint then the primary one :
sys@LION> alter table opt drop constraint opt_id_fk;
then,
sys@LION> alter table ersh_tab drop constraints emp_id_pk;
or to do it in one shot , you can try the following:
sys@LION> alter table ersh_tab drop constraints emp_id_pk cascade;
it will drop the dependent constraints also automatically.
Note : you can get the dependency information from dba_constraints/user_constraints/all_constraints view .
MORE ABOUT PRIMARY KEY
thanks,
Have a nice day .............
He who has never learned to obey
cannot be a good commander.
Aristotle
No comments:
Post a Comment