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.


Sachin Jain
Views: 96 | Community Opinion: 2



Bookmark this page..



Ask a New Question Go to Home

Community Opinion/Answers
 
vivek k Said..

Unique Key : a unique key can uniquely identify each row in a table.
Primary Key: Once you define a primary key row should not be blank at the time of inserting any data.once you define a primary key a particular column become a mandatory field. manadatory fields means you need to insert something on it.




vivek k Said..

WHERE clause is used to impose condition on SELECT statement as well as single row function and is used before GROUP BY clause where as HAVING clause is used to impose condition on GROUP Function and is used after GROUP BY clause in the query






Register or Login to Post Your Opinion