Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Foreign keys

Author  Topic 

tclose
Starting Member

24 Posts

Posted - 2010-04-28 : 19:29:31
Do tables always need foreign keys? What is an example situation in which they wouldn't if so.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-28 : 19:33:19
You wouldn't have a foreign key if no relation exists to other tables. An example from one of my systems is a timezone table. It's just there so that we can lookup the GMT offset and then use that to convert date/time of data.

Foreign keys are used to protect data, also know as data integrity.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-30 : 02:10:09
FK is easiest way to ensure relationship is correctly set between two tables. In absence of FK, you might need to implement a trigger to ensure this referential integrity. In case where there's no relation to another table, there's no need of FK.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -