Foreign Key Versus Table Index
| From: | J Hussein | Date: | Thu, 02 Oct 2008 10:25:22 +0000 |
| Subject: | Foreign Key Versus Table Index | ||
| References: | 1 2 3 4 5 6 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-45499@lists.php.net to get a copy of this message | ||
Hi,
I'm slightly confused about foriegn keys and indexes on mysql innodb tables.
Foreign key constraints create a reference between two tables and indexes make queries on a particular table faster if the index is on a field in the where or order by clause.
My question was whether say for the following two tables:
Person Car
Id Id Name PersonId Address Make Phone Number ColourIf I create a foriegn key linking the id field in person and the personid field in car, do I need to create another index in car table specifically for the personid field if I was running a query such as: "SELECT Id FROM car WHERE personid={personkeynumber}"? Thanks for your help. Jemma