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
 Primary Key vs Foreign Key

Author  Topic 

JJins
Yak Posting Veteran

81 Posts

Posted - 2010-10-19 : 11:42:40
I am having trouble understanding the relationship between Primary Keys and Foreign keys. Since I do not understand the relationship it is not allowing me to run queries and updates of my choice.

Can anyone explain how PK and FK work together or against each other.
Thanks as always.
Best,
GG

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-19 : 11:51:45
A primary key is an attribute (or combination of attributes) that uniquely identify each instance of an entity. A primary key cannot be null and the value assigned to a primary key should not change over time. A primary key also needs to be efficient. For example, a primary key that is associated with an INTEGER datatype will be more efficient than one that is associated with a CHAR datatype. Primary keys should also be non-intelligent; that is, their values should be assigned arbitrarily without any hidden meaning. Sometimes none of the attributes of an entity are sufficient to meet the criteria of an effective primary key. In this case the database designer is best served by creating an "artificial" primary key.


A "foreign key" exists when the primary key of a parent entity exists in a child entity. A foreign key requires that values must be present in the parent entity before like values may be inserted in the child entity. The concept of maintaining foreign keys is known as "referential integrity".

Source: http://www.sqlteam.com/article/database-design-and-modeling-fundamentals


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -