Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: How to add foreign key to a table
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
![]() |
![]() |