| Author: Sonu Fernandes 22 May 2008 | Member 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 2008 | Member 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 2008 | Member 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 2008 | Member 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 2008 | Member 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.
|