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

Home -> Community -> Mailing Lists -> Oracle-L -> Re: PK/Fk question

Re: PK/Fk question

From: Jonathan Lewis <jonathan_at_jlcomp.demon.co.uk>
Date: Mon, 27 Aug 2001 10:10:58 -0700
Message-ID: <F001.00378738.20010827101532@fatcity.com>

The opposite end of a 'foreign key' has to be a 'unique key' or 'primary key'. You have only two 'nominally correct' options -

  1. declare a unique key on table1.col1 or
  2. Create a table where the unique values of table1.col1 are held, and declare a primary key on it - them make table1 and table2 reference it.

Your question does, of course, suggest that there may be a flaw in your physical database structure.

Jonathan Lewis

Host to The Co-Operative Oracle Users' FAQ http://www.jlcomp.demon.co.uk/faq/ind_faq.html

Author of:
Practical Oracle 8i: Building Efficient Databases See http://www.jlcomp.demon.co.uk/book_rev.html

For latest news of public appearances
See http://www.jlcomp.demon.co.uk

Screen saver or Life saver: http://www.ud.com Use spare CPU to assist in cancer research.

-----Original Message-----
To: Multiple recipients of list ORACLE-L <ORACLE-L_at_fatcity.com> Date: 27 August 2001 17:42

|Hi DBAs,
|
|Table1 PK is on columns col1,col2,col3
|I want to create a FK on table2 to table1 for col1.
|
|What is the alternative to
|ALTER TABLE table2
|ADD CONSTRAINT fk_table2
|FOREIGN KEY (col1) REFERENCES table1(col1);
|
|I always get ORA-2270: No matching unique or primary key for this
|column-list.
|Every value for table2.col1 is in the table table1.col1. I want to
enforce
|this at the database server level.
|
|Thanks
|Rick

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Jonathan Lewis
  INET: jonathan_at_jlcomp.demon.co.uk

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Mon Aug 27 2001 - 12:10:58 CDT

Original text of this message

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