Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

composite keys

Status
Not open for further replies.

technohead

Technical User
Jan 12, 2002
64
0
0
US
Hi,
im creating a table with composite keys, that is the order_id and stock_id are primary keys, how do i do this

CREATE TABLE GIFT_ORDER_ITEM
(
ORDER_ID NUMBER,
STOCK_ID NUMBER,
QUANTITY NUMBER
)
 
something like
PRIMARY KEY (ORDER_ID NUMBER, STOCK_ID NUMBER)
 
Create the table then try two seperate alter commands:

Alter Table Gift_Order_Item
add primary key(order_id);

Alter Table Gift_Order_Item
add primary key(stock_id);

 
JMelvin: table can have only ONE primary key, so the second statement obviously will produce an error.

The correct syntax is

Alter Table Gift_Order_Item
add primary key(order_id, stock_id);

Or in one-shot with creating table:


CREATE TABLE GIFT_ORDER_ITEM
(
ORDER_ID NUMBER,
STOCK_ID NUMBER,
QUANTITY NUMBER,
primary key (ORDER_ID,STOCK_ID))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top