Home » SQL & PL/SQL » SQL & PL/SQL » How can I reference a Composite key??
How can I reference a Composite key?? [message #2094] Thu, 20 June 2002 12:30 Go to next message
Jzo
Messages: 4
Registered: June 2002
Junior Member
Hi, I would like to know How can I made a foreign key out of a Composite key. thanks in advance.
Re: How can I reference a Composite key?? [message #2096 is a reply to message #2094] Thu, 20 June 2002 12:41 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
sql>create table p (c1 int, c2 int, primary key (c1, c2));
 
Table created.
 
sql>create table c (x int, c1 int, c2 int, foreign key (c1, c2) references p);
 
Table created.
Re: How can I reference a Composite key?? [message #2098 is a reply to message #2094] Thu, 20 June 2002 12:43 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
you can do that.
The only restriction is that that the Primary key index should be in the same order.
SQL> ed
Wrote file afiedt.buf

  1  CREATE TABLE parent
  2  (
  3  year NUMBER(4) ,
  4  month NUMBER(2),
  5* constraint p_parent PRIMARY KEY  (year,month))
SQL> /

Table created.
SQL> ed
Wrote file afiedt.buf

  1  CREATE TABLE child
  2  (
  3  id VARCHAR2(7),
  4  year NUMBER(4),
  5  month NUMBER(2),
  6  constraint fk_child FOREIGN KEY (year, month)
  7* REFERENCES parent(year,month ))
SQL> /

Table created.
How do I set the value of a Composite Foreign Key ? [message #2112 is a reply to message #2094] Fri, 21 June 2002 02:15 Go to previous message
Mark Grimshaw
Messages: 73
Registered: June 2002
Member
Hello,

I have a table which has a foreign key defined as follows

CREATE TABLE TEST
( ...
TEST_ID VARCHAR2(4),
OTHER_TABLE, CONSTRAINT
FOREIGN_KEY fkey FOREIGN KEY(TEST_ID,OTHER_TABLE.ID)
REFERENCES OTHER_TABLE(TEST_ID,OTHER_TABLE.ID)
)/

The question is how do I set the OTHER_TABLE composite foreign key when using the SQL Loader tool or is this
field updated automatically by Oracle ?

TYIA
Previous Topic: urgent - in month and upto month figure in singe query
Next Topic: What is Query
Goto Forum:
  


Current Time: Fri Apr 26 21:20:11 CDT 2024