If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Indexing a Many to Many Table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-23-07, 12:03
ozzii ozzii is offline
Registered User
 
Join Date: Mar 2007
Posts: 194
Indexing a Many to Many Table

Hi,

I have many to many table called Jobseeker_IndustryExp. It has the following fields:

recordid - this auto increment number
jobseekerid - this foriegn key from jobseeker table
industryid this is foriegn key from industry table

Would you recomend indexing the jobseekerid and industryid fields in the above table - a frequent Select query will be used to do an inner join on the above table to search for jobseekers who match certain industry experience?
Reply With Quote
  #2 (permalink)  
Old 04-23-07, 12:28
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
Why do you have an auto_increment field in there? Surely because this is a mapping table you don't need that field. And i'm guessing (if you've designed your DB correctly) that the jobseekerid and industryid combination ought to be unique.

Personally I would do the following :
1) Remove the auto_increment
2) Create the primary key on (jobseekerid,industryid)
Reply With Quote
  #3 (permalink)  
Old 04-23-07, 14:43
ozzii ozzii is offline
Registered User
 
Join Date: Mar 2007
Posts: 194
Yep u right. both jobseekerid and industryid are unique primary keys of their respected tables. The recordid i just created - no particular reason! Whats the syntax for defining a compound primary key though?
Reply With Quote
  #4 (permalink)  
Old 04-23-07, 16:27
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by ozzii
Whats the syntax for defining a compound primary key though?
Code:
create table Jobseeker_IndustryExp
( jobseekerid integer not null 
, industryid  integer not null 
, primary key (jobseekerid, industryid)
, constraint job_fk
     foreign key (jobseekerid) references jobseeker
, constraint industry_fk
     foreign key (industryid) references industry 
);
say, ozzii, would you mind answering my question in this other thread?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On