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.

sql

This is a discussion on sql within the Database General forums, part of the Databases category; What is the difference between primary key and a unique key?...

Go Back   Geeks Talk > Databases > Database General
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read

Database General Database common Questions

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-11-2008
Junior Member
 
Join Date: Nov 2008
Location: india
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
such_rohit is on a distinguished road
Lightbulb sql

What is the difference between primary key and a unique key?
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-11-2008
Junior Member
 
Join Date: Jan 2006
Posts: 2
Thanks: 0
Thanked 2 Times in 2 Posts
meetsabir1@yahoo.com is on a distinguished road
Re: sql

Both primary key and unique key will unique,but in unique key it will allow one value to be null
Reply With Quote
The Following User Says Thank You to meetsabir1@yahoo.com For This Useful Post:
  #3 (permalink)  
Old 11-12-2008
Expert Member
 
Join Date: Nov 2008
Location: Chennai
Posts: 303
Thanks: 1
Thanked 37 Times in 32 Posts
amitpatel66 is on a distinguished road
Re: sql

Primary Key:

1. When created, an index gets created for the same.

2. Cannot hold NULL values

3. No duplicates allowed


Unique key

1. When created, index gets created for unique key also

2. Can hold NULL values.

3. no duplicates allowed
Reply With Quote
  #4 (permalink)  
Old 12-25-2008
Junior Member
 
Join Date: Dec 2008
Location: noida
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Nagesh4017 is on a distinguished road
Re: sql

There can be Single Null value in Unique key but Not in Primary Key
Reply With Quote
  #5 (permalink)  
Old 12-26-2008
Expert Member
 
Join Date: Apr 2007
Location: Bangalore
Posts: 515
Thanks: 29
Thanked 63 Times in 61 Posts
susarlasireesha will become famous soon enough
Re: sql

One more point..
There will be only primary key in a table and you can have any number of unique keys.
__________________
Sireesha
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: sql

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
  #7 (permalink)  
Old 06-18-2009
Contributing Member
 
Join Date: Jun 2009
Location: United States
Posts: 71
Thanks: 0
Thanked 5 Times in 4 Posts
CSOOR is on a distinguished road
Re: sql

Both should have unique keys to identify the rows but unique key can have null value
Reply With Quote
  #8 (permalink)  
Old 06-18-2009
Expert Member
 
Join Date: May 2009
Location: Bangalore
Posts: 984
Thanks: 155
Thanked 420 Times in 201 Posts
rijus is just really nicerijus is just really nicerijus is just really nicerijus is just really nicerijus is just really nice
Re: sql

Hi,

Primary key doesnot allow null value but unique key allows null value.

We can declare only one primary key in a table but a table can have multiple unique key(column assign).

Thanks &Regards,
Riju
Reply With Quote
Reply

  Geeks Talk > Databases > Database General

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



All times are GMT -4. The time now is 02:17 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