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 create primary key/foreign key?

Re: How to create primary key/foreign key?

From: Peter Schneider <peter.schneider_at_okay.net>
Date: Thu, 13 Aug 1998 19:40:17 GMT
Message-ID: <6qvffl$ibl$3@trader.ipf.de>


On Thu, 13 Aug 1998 12:07:56 -0500, paulsian_at_sprintmail.com (Paul Sian) wrote:

>I have a table where I need to create a primary key and a foreign key =
for
>the same column. How do I do this?
>Thanks

Hi Paul,

if you want to use named constraints, use:

ALTER TABLE <your_table> ADD
(CONSTRAINT <your_pk_name>
 PRIMARY KEY <col_1, ..., col_n>);

You could add a 'USING INDEX' clause to have control over storage parameters. Check the Oracle Server SQL Reference Guide for details.

For the foreign key, use:

ALTER TABLE <your_table> ADD
(CONSTRAINT <your_fk_name>
 FOREIGN KEY <col_1, ..., col_n>

 REFERENCES <master_table> (<master_tab.col_1, ..., master_tab.col_n>)  ON DELETE CASCADE); You can leave out the cascade option if you want this to be a restricted foreign key.

HTH
Peter

--
Peter Schneider
peter.schneider_at_okay.net Received on Thu Aug 13 1998 - 14:40:17 CDT

Original text of this message

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