Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: How to add foreign key to a table

Re: How to add foreign key to a table

From: Anne-Marie Ternes <anne-marie.ternes_at_cie.smtp.etat.lu>
Date: 1998/03/05
Message-ID: <34FEB779.77A5D852@cie.smtp.etat.lu>#1/1

Laura Bellini wrote:
>
> Hi -
>
> Can someone please tell me the SQL command(s) for adding a foreign key to a
> table? I want to be able to name the foreign key that I assign as well.
>
> thanks.

Here is the command for adding a foreign key constraint after creating the table. Note however that constraints should be defined at table creation, and not afterwards:

ALTER TABLE <tablename>

	ADD CONSTRAINT fk_<column name>
	FOREIGN KEY (<column name>)
	REFERENCES <parent table> (<column name>)

Try it out,

Anne-Marie Ternes

anne-marie.ternes_at_cie.etat.lu Received on Thu Mar 05 1998 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US