The title is a common question I've received in the past and I thought I'd take a few minutes to explain a bit about keys and indexes...
This is by no means a lot of detail regarding relational theory, etc. but there are a few things that we should quickly review to make sure that the basis for indexes being created makes sense. First, from a relational theory perspective every table must have a primary key. From SQL Server's perspective it's not a requirement but it's generally a good idea. A primary/unique key are entity identifiers. Each are a unique way of identifying a row. There are subtle differences between the two - in implementation:
Primary Key
Unique Key
What's the difference between a unique index and a unique constraint?
So, all of this leads me up to the original question (yes, you knew I get here someday :) and that's “When did SQL Server stop putting indexes on Foreign Key columns?”
First, SQL Server has NEVER put an index on a foreign key column... Indexes are used (as described above) to make the lookup (in a primary or unique key) for a duplicate value FAST. If the keys are ordered then checking to see if one already exists is trivial (i.e. fast). There is NO reason for SQL Server to put an index on a foreign key column as the column does not (and probably would never be) unique (if it is then it's likely to have a primary or unique key on it as well - as in a 1-1 relationship). So, that leads me to another key point...
Are there any benefits to indexing foreign key columns? YES
Finally, if you want a few titles related to relational theory check out these links:
An Introduction to Database Systems, Eighth Edition by C.J. Date E.F. Codd
Database Design for Mere Mortals: A Hands-On Guide to Relational Database Design Mike Hernandez
Have fun!kt
Theme design by Jelle Druyts
Pick a theme: BlogXP sqlx BlogXP sqlx
Powered by: newtelligence dasBlog 2.0.7226.0
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2008, Kimberly L. Tripp
E-mail