List:General Discussion« Previous MessageNext Message »
From:Wagyu Beef Date:March 1 2011 12:23pm
Subject:Newbie question: Association table and Foreign Key
View as plain text  
Hey guys,

Am a newbie here and need a little help.

Part of the database consists of two tables "events" and "categories" which
look like this

+-------------------+-------------------------+
 |  eventID       |     eventName     |
+-------------------+-------------------------+
 |       1           |     Event A          |
 |       2           |     Event B          |
 |       3           |     Event C          |
+-------------------+-------------------------+
Primary Key: eventID

+-------------------+-------------------------+
 |  categoryID  |   categoryName   |
+-------------------+-------------------------+
 |       1           |     Category A     |
 |       2           |     Category B     |
 |       3           |     Category C     |
+-------------------+-------------------------+

Primary Key: categoryID


The idea is that an event may have multiple categories and from what I've
read here (http://lists.mysql.com/mysql/171645), many-to-many relationships
in the database should be avoid.  According to the link and a couple of
others I found, I'm supposed to create a separate "events_categories" table
and make linkages using a Foreign Key.  Am not sure how to translate this to
a SQL query.  Can I get some help.

Thanks a million!

Regards,
Suren

Thread
Newbie question: Association table and Foreign KeyWagyu Beef1 Mar
  • Re: Newbie question: Association table and Foreign KeyDhaval Jaiswal1 Mar
    • Re: Newbie question: Association table and Foreign KeyWagyu Beef1 Mar
  • Re: Newbie question: Association table and Foreign Keyhsv2 Mar