AnonymousGal AnonymousGal - 17 days ago 6
SQL Question

Is there a way to have a table having 2 columns that are foreign keys referencing 2 other tables?

I have 3 tables Customer, Store and Receipt. The Receipt table must have a receiptno which is the primary key. Also the Receipt table has attributes customerid and storeid, how to I specify that customerid is a foreign key that references customerid in the customer table AND storeid is a foreign key that references storeid in the Stores table?

Answer
create table Customer (customerid int primary key);
create table Store    (storeid    int primary key);

create table Receipt  
(
    receiptno  int primary key
   ,customerid int references Customer (customerid)
   ,storeid    int references Store    (storeid)   
 );