Subject | Index design questions |
---|---|
Author | Marcin Bury |
Post date | 2010-04-08T16:54:11Z |
Hello all
Let's say I have two tables:
1. Customers
- Customer_ID - Primary Key
... other customer fields
2. Delivery_Locations
- Location_ID - Primary Key
... other location fields
Since one customer can have many delivery locations and one location can
serve many customers I know I need third table:
Customers_Locations
- Customer_ID
- Location_ID
It's obvious that in this table can be only one pair of certain customer
and location, so it looks that having compound primary key based on both
columns is good idea, but...
I need to select locations for certain customer and select customers for
certain location. Adding second index but with opposite order of columns
will be also good idea?
Primary Key: Customer_ID, Location_ID
Additional Index: Location_ID, Customer_ID
Or maybe there is more elegant solution?
TIA
Marcin
Let's say I have two tables:
1. Customers
- Customer_ID - Primary Key
... other customer fields
2. Delivery_Locations
- Location_ID - Primary Key
... other location fields
Since one customer can have many delivery locations and one location can
serve many customers I know I need third table:
Customers_Locations
- Customer_ID
- Location_ID
It's obvious that in this table can be only one pair of certain customer
and location, so it looks that having compound primary key based on both
columns is good idea, but...
I need to select locations for certain customer and select customers for
certain location. Adding second index but with opposite order of columns
will be also good idea?
Primary Key: Customer_ID, Location_ID
Additional Index: Location_ID, Customer_ID
Or maybe there is more elegant solution?
TIA
Marcin