List:General Discussion« Previous MessageNext Message »
From:Daevid Vincent Date:March 18 2003 11:50pm
Subject:Please tell me why to use KEY (a_id, b_id) rather than KEY (a_id), KEY (b_id)
View as plain text  
I wouldn't say I was a newbie at all. I've been coding in PHP, mySQL for
like 6 years now. But I just never learned (or maybe had a reason to) why I
would use "KEY (a_id, b_id)" rather than "KEY (a_id)" and "KEY (b_id)".
Would someone be so kind as to point me at an online tutorial or just
explain what the difference is or what the use of "KEY (a_id, b_id)", and
does it matter if I reverse them like "KEY (b_id, a_id)"? I mean, I
understand that the key will be a hybrid of the two columns, but why would
you want that? A friend tried to explain it in the case you have a third
table that is what I call a "glue" table, but I still don't see how this
works.

CREATE TABLE parent
(
  par_id   INT NOT NULL,
  PRIMARY KEY (par_id)
) TYPE = INNODB;

CREATE TABLE child
(
  par_id   INT NOT NULL,
  child_id  INT NOT NULL,
  PRIMARY KEY (par_id, child_id),
  FOREIGN KEY (par_id) REFERENCES parent (par_id) ON DELETE CASCADE
) TYPE = INNODB;

Btw, I saw this here:
http://165.193.123.40/isapi/product_id~%7B60B19985-0F7B-4E72-88ED-C472616E45
D8%7D/element_id~%7BF31998C7-4725-4997-AB4A-09AC0D03A6B3%7D/st~%7B822202F4-E
865-472D-B32F-BE77D3B7ACE1%7D/content/articlex.asp

Which is a great tutorial on mySQL by Paul Dubois.

Thread
Please tell me why to use KEY (a_id, b_id) rather than KEY (a_id), KEY (b_id)Daevid Vincent19 Mar
  • Re: Please tell me why to use KEY (a_id, b_id) rather than KEY (a_id), KEY (b_id)Dan Nelson19 Mar
RE: Please tell me why to use KEY (a_id, b_id) rather than KEY (a_id), KEY (b_id)Daevid Vincent19 Mar
  • Re: Please tell me why to use KEY (a_id, b_id) rather than KEY (a_id), KEY (b_id)Jeff Kilbride19 Mar
  • Re: Please tell me why to use KEY (a_id, b_id) rather than KEY (a_id),KEY (b_id)Bruce Feist19 Mar