Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Foreign Key Constraint

Status
Not open for further replies.

JTOracle

Programmer
Apr 19, 2002
4
US
I need to remove a FOREIGN KEY constraint to add new data but I can't seem to do it.
I know it would be:
ALTER TABLE Clients DROP CONSTRAINT constraint_name
but that is if you gave the constraint a name, I created the foreign key constraint when I created the table, and did not designate a name (i.e. FOREIGN KEY (branchNo) references Branch(branchNo)
I would like to Drop the table and start over but it has a primary key which is referenced elsewhere.
How can I get rid of this constraint?

Thanks
 
If you don't know the name of the foreign key, you should be able to find it with the following query. Then you can plug it into your drop statement.

select constraint_name from user_constraints
where table_name = 'CLIENTS'
and constraint_type = 'R';

If you have more than one foreign key defined on the clients table, you will have to find out which one is right. One way to do this is with the query

select constraint_name from user_cons_columns
where table_name = 'CLIENTS'
and column_name = 'BRANCHNO';
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top