What is the different between Primary key and Identity Column? and when should I them?
(Im just a beginner with databases...)
A primary key is a column that has only unique entries and is used as the key to that table, often by other tables as a foreign key. It can be an Identity, but it doesn;t have to be. An identity is a unique, system assigned data entry that guarantees uniqueness and is often apporpriately used as a primary key in a table.
For example, let's say you had 20 people in a table, and you recorded each with their different phone number. Since the phone is unique it could be a primary key. But now, suppose you want to add someone who lives in the same house as someone already in your table. Their phone can't match anyone else's since that violates the uniqueness of the primary key. You need to give them a dummy phone number, which is useless data. Using an identity column solves that, and even if someone moves and changes phone number, the primary key in the identity stays the same.
Jeff
No comments:
Post a Comment