C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




difference between a primary key and a unique key


Posted Date: 06 May 2008    Resource Type: Definitions    Category: General

Posted By: karthik       Member Level: Diamond
Rating:     Points: 5



What’s the difference between a primary key and a unique key?

Both primary key and unique enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a nonclustered index by default. Another major difference is that, primary key doesn’t allow NULLs, but unique key allows one NULL only.





Responses

Author: Sonu Fernandes    22 May 2008Member Level: Gold   Points : 2
Q:-What’s the difference between a primary key and a unique key?

A:- Both Primary Key and Unique Key enforces uniqueness of the column on which they are defined. But by default Primary Key creates a Clustered Index on the column, where are Unique Key creates a Nonclustered Index by default. Another major difference is that, Primary Key doesn’t allow NULLs, but Unique Key allows one NULL only.



Author: Siva Prasad    22 May 2008Member Level: Gold   Points : 2
Hello Karthik,

Additional to the RK Fernandes

Unique key allows one null value, but the primary key doesn't allow null value.

Siva Prasad


Author: UltimateRengan    20 Aug 2008Member Level: Diamond   Points : 2
hi,

Primary key and unique key does not allow enter duplicate data.
Primary key and unique are Entity integrity constraints.unique key can be null but primariy key cant be null.
primariy key can be refrenced to other table as FK.We can declare only one primary key in a table but a table can have multiple unique key(column assign




Author: Vijayaragavan.R    27 Aug 2008Member Level: Bronze   Points : 2
PRIMARY refers to a field or a set of fields used to identify each row in a table. UNIQUE refers to a field that cannot be repeated in a table. The primary key is, by necessity, a unique identifier, but any field may be defined as unique. The primary key can be a composite, consisting of more than one field. Each field within a composite key can be repeated, but each combination of fields must be unique.


Author: Vijayaragavan.R    27 Aug 2008Member Level: Bronze   Points : 2
Primary Key - This is an index that cannot be NULL, Primary Keys are used in building relationships between tables in a database. (an index is automatically created on the primary key). The difference between primary and ordinary keys is that there can be multiple keys, but only one primary key.

Unique Key - Unique and Index are same, the difference is, in Unique, duplicate are not allowed in any circumstances and that is enforced by database server. Primary key(s) qualify to be Unique on basis of their uniqueness.
In case, your table has 2 primary keys means that the 2 fields together form one unique key. Each field by itself may have repeating values, but both primary keys combined together must be unique.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Difference between OLEDB Provider and SqlClient
Previous Resource: deadlock
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

audio conferencing services

Contact Us    Privacy Policy    Terms Of Use