Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » primary key versus unique key
Closed Thread
Old 01-13-2006, 09:30 AM   #1 (permalink)
 
Newb Techie

Join Date: Jan 2006

Posts: 12

techno_kid

Default primary key versus unique key

what is the difference between primary key and unique key?

thanks a lot.. =)
techno_kid is offline  
Old 01-13-2006, 10:40 AM   #2 (permalink)
 
Newb Techie

Join Date: Dec 2005

Posts: 11

snif innards

Default

a primary key has to be a unique key but, a unique key dosen't have to be a primary key
snif innards is offline  
Old 01-13-2006, 11:03 PM   #3 (permalink)
 
Newb Techie

Join Date: Jan 2006

Posts: 12

techno_kid

Default

oh i see =)
but is it only the difference? i mean, what are their specific purposes?
primary key is primarily for what?
and unique key is basically for what?

im a newbie in database programming.. =)
thanks snif...
i appreciate your help.. =)
techno_kid is offline  
Old 01-14-2006, 04:25 AM   #4 (permalink)
Chankama's Avatar
 
Monster Techie

Join Date: Jan 2005

Location: Canada

Posts: 1,522

Chankama will become famous soon enough

Default

Well.. A primary key is something that is used for indexing the rows of a database. Naturally, it has to be unique. But, I guess you could have unique keys that are not necessarily primary keys. The uniqueness of the column could be a constraint of the database for example.

A person Social Insurance Number and Drivers License Number can be two unique keys that "must" be enforced at all times. But, only one of them needs to be selected as a primary key. If you don't want to, then you can introduce a surrogate key that is auto-generated by the databse system everytime you create a new row.
Chankama is offline  
Old 01-14-2006, 07:53 PM   #5 (permalink)
 
Newb Techie

Join Date: Jan 2006

Posts: 12

techno_kid

Default

thanks chankama..
that's a great help... =)
techno_kid is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On