View Single Post
  #13 (permalink)  
Old 03-04-10, 18:28
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by misticism View Post
R937: Do you mean make each of those items a primary key, or do you mean to some how link them so that they are as a group a single primary key? If the later, how do I do that?
yes, the latter
Code:
CREATE TABLE user_creature_link 
( user_id INTEGER NOT NULL 
, creature_id INTEGER NOT NULL 
, PRIMARY KEY ( user_id , creature_id )
, FOREIGN KEY ( user_id ) REFERENCES users (id ) ON DELETE CASCADE
, FOREIGN KEY ( creature_id ) REFERENCES creatures (id ) ON DELETE CASCADE
);
Quote:
Originally Posted by misticism View Post
... it seems like a very important part of MySQL
foreign keys are an essential part of all relational databases, not just mysql
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Last edited by r937; 03-04-10 at 18:32.
Reply With Quote