dbTalk Databases Forums  

Multiple Foreign Keys

comp.databases comp.databases


Discuss Multiple Foreign Keys in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
chris.danx
 
Posts: n/a

Default Multiple Foreign Keys - 07-08-2003 , 10:59 AM






Hi,

How are foreign keys defined in SQL? From my notes and text there are
two ways, one of which can be used when you have multiple foreign keys,
the other cannot. It's looks like the following is supposed to be the
right one, but this doesn't work in MySQL*. I suppose it could be a
vendor thing... but I'm not so sure having read over the examples and
notes in the manual (all these different implementations and their
friggin' variations on SQL! )


Code:
CREATE TABLE Likes
(
drinker VARCHAR(20),
beer VARCHAR(20),

PRIMARY KEY (drinker,beer),
FOREIGN KEY drinker
REFERENCES Drinkers(name)
);



I tried extending it with

Code:
CREATE TABLE Likes
(
drinker VARCHAR(20),
beer VARCHAR(20),

PRIMARY KEY (drinker,beer),
FOREIGN KEY drinker, beer
REFERENCES Drinkers(name), Beers(name)
);


and ...

Code:
CREATE TABLE Likes
(
drinker VARCHAR(20),
beer VARCHAR(20),

PRIMARY KEY (drinker,beer),
FOREIGN KEY drinker
REFERENCES Drinkers(name),
FOREIGN KEY Beers
REFERENCES Beer(name)
);



but MySQL doesn't want to play. What's the correct syntax or one of the
above fine and it is a MySQL peculiarity? My text doesn't show an
example of multiple foreign keys at all.



Cheers,
Danx

*I'm ignoring the fact MySQL doesn't pay any attention to foreign keys
in general, it's not important. The purpose is to learn SQL.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.