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

Home -> Community -> Usenet -> c.d.o.server -> Re: Multi-column keys: Multi-questions

Re: Multi-column keys: Multi-questions

From: Gary Gapinski <gary.gapinski_at_eds.com>
Date: Thu, 09 Dec 1999 16:44:50 -0500
Message-ID: <385022D2.38510166@eds.com>


"Robert R. Wagner" wrote:
>
> I have a tableA with multiple columns forming a primary key and tableB using
> that key as a foreign key. They tables were converted from Access by the
> conversion wizard, so I'm not really sharp on creating similar relationships
> for new tables, which I will soon need to do.
>
> If I were starting from scratch:
> 1) How would I create the multicolumn primary key in TableA using
> SQL*PLUS?
Either at creation time
CREATE TABLE TableA ...
CONSTRAINT [<name>] PRIMARY KEY (column1, column2, ..., column)

or subsequently

ALTER TABLE TableA
CONSTRAINT [<name>] PRIMARY KEY (column1, column2, ..., column)

> 2) How would I create the foreign key in TableB?

Either at creation time
CREATE TABLE TableB ...
CONSTRAINT [<name>] FOREIGN KEY (column1, column2, ..., column) REFERENCES TableA [(column1, column2, ..., column)]

or subsequently
ALTER TABLE TableB ...
CONSTRAINT [<name>] FOREIGN KEY (column1, column2, ..., column) REFERENCES TableA [(column1, column2, ..., column)]

>
> Once created, in SQL*PLUS, how do I see the names of the columns that form
> TableA's primary key?

I don't know of an easy way other than to reference (USER|ALL|DBA)_CONS_COLUMNS, possibly joined with (USER|ALL|DBA)_CONSTRAINTS.
>
> Lastly, must the column names in tableB's foreign key be the same as those
> forming the primary key in TableA?

No. The specific (TableB) column names must be cited. TableA's columns, if not specified, imply TableA's primary key.

Note that there are other potential values to the CREATE TABLE and ALTER TABLE statements, including physical storage parameters, multiple FOREIGN KEY clauses, and the like.

Regards,

Gary Received on Thu Dec 09 1999 - 15:44:50 CST

Original text of this message

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