Overview

You may know that it is best practice to create FOREIGN KEY constraints on related tables in a database.  Why is this?

Details

A foreign key constraint can be used for:

  • Ensuring referential integrity: a foreign key constraint can ensure database consistency
  • Self-documenting databases: the foreign key clause can be viewed in the database and describes a relationship
  • Efficiency: even without an index, the SQL Server engine recognises the constraint and uses it to optimise table joins automatically

Generally, you will also want to index the foreign key columns in the table, but it is worth adding the FOREIGN KEY constraint even if you don't create the index because it helps the database to optimise the execution plan.

References

Versions

Metadata


Bookmark with :
Digg It! DZone StumbleUpon Technorati Reddit Del.icio.us Newsvine Furl Blinklist
posted @ Friday, January 11, 2008 3:31 PM | in SQL Server Software Development IT Management

Comments

No comments posted yet.

Post Comment

Title *
Name *
Email
Url
Comment *  


Please add 3 and 7 and type the answer here: