Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

difference between unique key and primary key

This is a discussion on difference between unique key and primary key within the SQL forums, part of the Databases category; need answer...

Go Back   Geeks Talk > Databases > SQL
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 03-02-2009
Junior Member
 
Join Date: Mar 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Suraen is on a distinguished road
difference between unique key and primary key

need answer
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-02-2009
Moderator
 
Join Date: Jun 2007
Location: Bangalore,India
Posts: 1,860
Thanks: 9
Thanked 168 Times in 142 Posts
debasisdas has a spectacular aura aboutdebasisdas has a spectacular aura about
Re: difference between unique key and primary key

unique key enforces only uniqueness--ie--no duplicate value

primary key enforces both uniqueness and not null
an index is also created on primary key field.
Reply With Quote
The Following 2 Users Say Thank You to debasisdas For This Useful Post:
  #3 (permalink)  
Old 03-03-2009
Contributing Member
 
Join Date: Jan 2009
Posts: 31
Thanks: 0
Thanked 3 Times in 3 Posts
chaitra murthy is on a distinguished road
Re: difference between unique key and primary key

In addition:-
Table shoud have only one promary key where as it can have more than one unique key.
Reply With Quote
  #4 (permalink)  
Old 03-04-2009
Expert Member
 
Join Date: Jun 2007
Location: Australia
Posts: 260
Thanks: 7
Thanked 15 Times in 15 Posts
Sushma Mosali is on a distinguished road
Re: difference between unique key and primary key

A unique key must uniquely identify all possible rows that exist in a table and not only the currently existing rows. Examples of unique keys are Social Security numbers (associated with a specific person[1]) or ISBNs (associated with a specific book). Telephone books and dictionaries cannot use names or words or Dewey Decimal system numbers as candidate keys because they do not uniquely identify telephone numbers or words.

A primary key is a special case of unique keys. The major difference is that for unique keys the implicit NOT NULL constraint is not automatically enforced, while for primary keys it is. Thus, the values in a unique key columns may or may not be NULL. Another difference is that primary keys must be defined using another syntax.

For more information refer to the following link

Unique key - Wikipedia, the free encyclopedia

Thanks
Sushma
Reply With Quote
The Following User Says Thank You to Sushma Mosali For This Useful Post:
  #5 (permalink)  
Old 03-04-2009
Junior Member
 
Join Date: Nov 2007
Location: Pune
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
prashantpurohit2000 is on a distinguished road
Thumbs down Re: difference between unique key and primary key

Quote:
Originally Posted by Sushma Mosali View Post
A unique key must uniquely identify all possible rows that exist in a table and not only the currently existing rows. Examples of unique keys are Social Security numbers (associated with a specific person[1]) ...
Hi Sushma, Please don't mind but people want explanation in our words, you need not work like an agent who does wiki search for questions.
Reply With Quote
  #6 (permalink)  
Old 03-13-2009
Junior Member
 
Join Date: Feb 2009
Location: india
Posts: 21
Thanks: 0
Thanked 13 Times in 9 Posts
nithui is on a distinguished road
Re: difference between unique key and primary key

hai,
The column holding the primary key constraint cannot accept
null values.whereas column holding the unique constraint can
accept null values assume that t3 is a table with two
columns t1 having primary key constraint and t2 having
unique constraint if u try to insert null into t2 it will
accept that values whereas column t1 will not accept null
Regards,
Nithya.R
Reply With Quote
The Following User Says Thank You to nithui For This Useful Post:
  #7 (permalink)  
Old 03-18-2009
Junior Member
 
Join Date: Feb 2009
Location: lucknow
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
poonamjoshi10 is on a distinguished road
Re: difference between unique key and primary key

In a table there can be multiple unique keys but there can be only one primary key.
Unique key can be defined as null but primary key cann't be set to null.
Reply With Quote
  #8 (permalink)  
Old 03-18-2009
Junior Member
 
Join Date: May 2006
Location: india
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
venugec is on a distinguished road
Re: difference between unique key and primary key

Unique key--The data in the column is unique. i.e if you specify NULL that should be only one NULL value

Primary key--No NULL at all
Reply With Quote
The Following User Says Thank You to venugec For This Useful Post:
  #9 (permalink)  
Old 03-18-2009
Junior Member
 
Join Date: Nov 2007
Location: Pune
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
prashantpurohit2000 is on a distinguished road
Re: difference between unique key and primary key

This is perfect!!!
Reply With Quote
  #10 (permalink)  
Old 03-18-2009
Junior Member
 
Join Date: Mar 2009
Location: india
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
sriramswati is on a distinguished road
Re: difference between unique key and primary key

perfect ........
Reply With Quote
  #11 (permalink)  
Old 04-02-2009
Junior Member
 
Join Date: Mar 2009
Location: mysore
Posts: 25
Thanks: 9
Thanked 0 Times in 0 Posts
shilpamj is on a distinguished road
Re: difference between unique key and primary key

both are using uniquely identify a row
but
a table can have more than 1 unique keys.a tabe can have only one primary key
and unique key allows NULL values but primary key never allows NULL values
Reply With Quote
  #12 (permalink)  
Old 08-11-2009
Junior Member
 
Join Date: Aug 2009
Location: mumbai
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
manapurimahesh is on a distinguished road
Re: difference between unique key and primary key

diffrence between SQL UNIQUE Constraint and sql primary key
Reply With Quote
  #13 (permalink)  
Old 08-11-2009
Moderator
 
Join Date: Jun 2007
Location: Bangalore,India
Posts: 1,860
Thanks: 9
Thanked 168 Times in 142 Posts
debasisdas has a spectacular aura aboutdebasisdas has a spectacular aura about
Re: difference between unique key and primary key

you need to go through other posts in this thread.
Reply With Quote
  #14 (permalink)  
Old 09-03-2009
Junior Member
 
Join Date: Aug 2009
Location: Delhi
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
sunil.bisht12 is on a distinguished road
Re: difference between unique key and primary key

primary key--> primary key is uniqe column in particular table and null value is not allow or other words duplicate value not allow as well as null value is not accepted.. in one table have only one primary key it called primary key

unique key--> unique key is same as primary key but in unique key allow null value
Reply With Quote
  #15 (permalink)  
Old 09-07-2009
Junior Member
 
Join Date: Feb 2009
Location: ongole
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
chiru0106 is on a distinguished road
Re: difference between unique key and primary key

difference between unique and primary key is


unique identifies only unique values(including null values )

primary key identifies only unique(but not null values)
Reply With Quote
  #16 (permalink)  
Old 09-10-2009
Junior Member
 
Join Date: Sep 2009
Location: haridwar
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
snlsth is on a distinguished road
Re: difference between unique key and primary key

Quote:
Originally Posted by Suraen View Post
need answer
unique should contain the null value but primary key cannot take a null value
Reply With Quote
  #17 (permalink)  
Old 4 Weeks Ago
Junior Member
 
Join Date: Oct 2009
Location: India
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
SPareek is on a distinguished road
Re: difference between unique key and primary key

1. Primary Key doesn't allow a null value but Unique key can have at most one null value.
2. Only one Primary key can be declared in a table but there can be multiple unique keys in a table.
Reply With Quote
  #18 (permalink)  
Old 4 Weeks Ago
Junior Member
 
Join Date: Oct 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
sugarnspice is on a distinguished road
Re: difference between unique key and primary key

unique key can have more than one null value! primary key cannot have null values at all... both can be referenced by foreign keys...but u can hav only 1 primary key but any number of unique keys...
Reply With Quote
Reply

  Geeks Talk > Databases > SQL

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 On
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
difference bet unique and distinct smitai Oracle Certification 4 4 Weeks Ago 08:35 AM
Initializing Primary Key PRINCEJOHNWESLEY MY SQL 0 09-10-2008 09:57 AM
difference between unique and distinct arpitace Oracle 2 08-12-2008 08:17 AM
Primary Key References krishnaindia2007 Oracle 1 03-06-2008 07:38 AM
what is the difference between Primary Key and Index Key ? skravipati SQL 1 09-07-2007 01:46 AM


All times are GMT -4. The time now is 03:14 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved