<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>Database Journal Forums - Oracle</title>
		<link>http://forums.databasejournal.com</link>
		<description>Discuss anything related to Oracle databases, from installation, development, maintenance, performance, security and certification.</description>
		<language>en</language>
		<lastBuildDate>Thu, 17 May 2012 16:29:41 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://forums.databasejournal.com/images/misc/rss.jpg</url>
			<title>Database Journal Forums - Oracle</title>
			<link>http://forums.databasejournal.com</link>
		</image>
		<item>
			<title>no matching unique or primary key</title>
			<link>http://forums.databasejournal.com/showthread.php?t=53187&amp;goto=newpost</link>
			<pubDate>Wed, 25 Apr 2012 15:36:17 GMT</pubDate>
			<description>Trying to create a table with a Foreign Key and getting the above error. 

The first table creates fine:

Code:
---------
CREATE TABLE ORDERS 
 (
    ORDERS_NUM         NUMBER       NOT NULL,
    CUST_NUM           NUMBER       NOT NULL,
    SHIP_STREET        VARCHAR(20)  NOT NULL,
    SHIP_CITY          VARCHAR(20)  NOT NULL,
    SHIP_STATE         VARCHAR(2)   NOT NULL,
    SHIP_ZIP           VARCHAR(5)   NOT NULL,
    SHIP_METHOD        VARCHAR(10)          ,
    ORDER_DATE         DATE         NOT NULL,
    SHIP_DATE          DATE                 ,
    PRIMARY KEY   (ORDERS_NUM, CUST_NUM),
    FOREIGN KEY   (CUST_NUM) REFERENCES CUSTOMER(CUST_NUM)
 );
---------
The second table is where I get the error:

Code:
---------
CREATE TABLE ORDERDETAIL
(
    DETAIL_NUM         NUMBER       NOT NULL,
    ORDERS_NUM         NUMBER       NOT NULL,
    PROD_NUM           NUMBER       NOT NULL,
    PROD_PRICE         DEC(10,2)            ,
    PROD_SHIP_COST     DEC(10,2)            ,
    QTY_PURCH          DEC(10,2)    NOT NULL,
    TOT_ORDER_WGHT     DEC(10,2)            ,
    ORDER_STAT	       DEC(10,2)    NOT NULL,
    TOT_PROD_COST      DEC(10,2)            ,
    TAX_RATE_ST        DEC(10,2)            ,
    ORDER_TAX          DEC(10,2)            ,
    TOT_SHIP_COST      DEC(10,2)            ,
    TOT_ORD_COST       DEC(10,2)            ,
    PRIMARY KEY   (DETAIL_NUM),
    FOREIGN KEY   (ORDERS_NUM) REFERENCES ORDERS(ORDERS_NUM),
    FOREIGN KEY   (PROD_NUM) REFERENCES PRODUCT(PROD_NUM)
);
---------
Error is on this line:

Code:
---------
    FOREIGN KEY   (ORDERS_NUM) REFERENCES ORDERS(ORDERS_NUM),
                                                 *
ERROR at line 17:
ORA-02270: no matching unique or primary key for this column-list
---------
New to SQL, Can someone please assist? I am using Oracle SQL Plus.</description>
			<content:encoded><![CDATA[<div>Trying to create a table with a Foreign Key and getting the above error. <br />
<br />
The first table creates fine:<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">CREATE TABLE ORDERS <br />
&nbsp;(<br />
&nbsp; &nbsp; ORDERS_NUM&nbsp; &nbsp; &nbsp; &nbsp;  NUMBER&nbsp; &nbsp; &nbsp;  NOT NULL,<br />
&nbsp; &nbsp; CUST_NUM&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  NUMBER&nbsp; &nbsp; &nbsp;  NOT NULL,<br />
&nbsp; &nbsp; SHIP_STREET&nbsp; &nbsp; &nbsp; &nbsp; VARCHAR(20)&nbsp; NOT NULL,<br />
&nbsp; &nbsp; SHIP_CITY&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VARCHAR(20)&nbsp; NOT NULL,<br />
&nbsp; &nbsp; SHIP_STATE&nbsp; &nbsp; &nbsp; &nbsp;  VARCHAR(2)&nbsp;  NOT NULL,<br />
&nbsp; &nbsp; SHIP_ZIP&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  VARCHAR(5)&nbsp;  NOT NULL,<br />
&nbsp; &nbsp; SHIP_METHOD&nbsp; &nbsp; &nbsp; &nbsp; VARCHAR(10)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,<br />
&nbsp; &nbsp; ORDER_DATE&nbsp; &nbsp; &nbsp; &nbsp;  DATE&nbsp; &nbsp; &nbsp; &nbsp;  NOT NULL,<br />
&nbsp; &nbsp; SHIP_DATE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DATE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  ,<br />
&nbsp; &nbsp; PRIMARY KEY&nbsp;  (ORDERS_NUM, CUST_NUM),<br />
&nbsp; &nbsp; FOREIGN KEY&nbsp;  (CUST_NUM) REFERENCES CUSTOMER(CUST_NUM)<br />
&nbsp;);</code><hr />
</div>The second table is where I get the error:<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">CREATE TABLE ORDERDETAIL<br />
(<br />
&nbsp; &nbsp; DETAIL_NUM&nbsp; &nbsp; &nbsp; &nbsp;  NUMBER&nbsp; &nbsp; &nbsp;  NOT NULL,<br />
&nbsp; &nbsp; ORDERS_NUM&nbsp; &nbsp; &nbsp; &nbsp;  NUMBER&nbsp; &nbsp; &nbsp;  NOT NULL,<br />
&nbsp; &nbsp; PROD_NUM&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  NUMBER&nbsp; &nbsp; &nbsp;  NOT NULL,<br />
&nbsp; &nbsp; PROD_PRICE&nbsp; &nbsp; &nbsp; &nbsp;  DEC(10,2)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,<br />
&nbsp; &nbsp; PROD_SHIP_COST&nbsp; &nbsp;  DEC(10,2)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,<br />
&nbsp; &nbsp; QTY_PURCH&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DEC(10,2)&nbsp; &nbsp; NOT NULL,<br />
&nbsp; &nbsp; TOT_ORDER_WGHT&nbsp; &nbsp;  DEC(10,2)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,<br />
&nbsp; &nbsp; ORDER_STAT&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  DEC(10,2)&nbsp; &nbsp; NOT NULL,<br />
&nbsp; &nbsp; TOT_PROD_COST&nbsp; &nbsp; &nbsp; DEC(10,2)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,<br />
&nbsp; &nbsp; TAX_RATE_ST&nbsp; &nbsp; &nbsp; &nbsp; DEC(10,2)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,<br />
&nbsp; &nbsp; ORDER_TAX&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DEC(10,2)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,<br />
&nbsp; &nbsp; TOT_SHIP_COST&nbsp; &nbsp; &nbsp; DEC(10,2)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,<br />
&nbsp; &nbsp; TOT_ORD_COST&nbsp; &nbsp; &nbsp;  DEC(10,2)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,<br />
&nbsp; &nbsp; PRIMARY KEY&nbsp;  (DETAIL_NUM),<br />
&nbsp; &nbsp; FOREIGN KEY&nbsp;  (ORDERS_NUM) REFERENCES ORDERS(ORDERS_NUM),<br />
&nbsp; &nbsp; FOREIGN KEY&nbsp;  (PROD_NUM) REFERENCES PRODUCT(PROD_NUM)<br />
);</code><hr />
</div>Error is on this line:<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">&nbsp; &nbsp; FOREIGN KEY&nbsp;  (ORDERS_NUM) REFERENCES ORDERS(ORDERS_NUM),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  *<br />
ERROR at line 17:<br />
ORA-02270: no matching unique or primary key for this column-list</code><hr />
</div>New to SQL, Can someone please assist? I am using Oracle SQL Plus.</div>

]]></content:encoded>
			<category domain="http://forums.databasejournal.com/forumdisplay.php?f=5">Oracle</category>
			<dc:creator>rcanter</dc:creator>
			<guid isPermaLink="true">http://forums.databasejournal.com/showthread.php?t=53187</guid>
		</item>
	</channel>
</rss>

