Primary key and unique are Entity integrity constraints
Primary key allows each row in a table to be uniquely identified and ensures that no duplicate rows exist and no null values are entered.
Unique key constraint is used to prevent the duplication of key values within the rows of a table and allow null values. (In oracle, one null is not equal to another null).
Above answer was rated as good by the following members: aravindmca08
RE: what is difference between "Primary key" and "Uniq...
A unique key has the property that no two values in the range are the same. A primary key is chosen from among all the unique keys of a table to participate in referential integrity constraints. Primary keys are unique by definition.
RE: what is difference between "Primary key" and "Uniq...
Primary key and unique are Entity integrity constraints
Primary key allows each row in a table to be uniquely identified and ensures that no duplicate rows exist and no null values are entered.
Unique key constraint is used to prevent the duplication of key values within the rows of a table and allow null values. (In oracle one null is not equal to another null).
RE: what is difference between "Primary key" and "Uniq...
sorry rana unique constraints do not include null. Null is not a value it's a state where the value is unknown. In DB2 a unique constraint MUST include the NOT NULL clause.
Even if allowed the index used to guarantee uniqueness could at most have one entry for NULL. This would assume that NULL was treated as a value. DB2 has a special property for an index namely: UNIQUE WHERE NOT NULL which allows multiple instances of NULL but forces unique values. This is good for M:1 relations where the many side is optional in the relationship. DB2's index is a very special case. Don't go looking for it in other RDBMS products.
RE: what is difference between "Primary key" and "Uniq...
Primary Key:- Primary Key is an attribute or a set of attributes in a table which uniquely identifies a record (row) in a table and no two records (rows) in the table can have the same values for all the columns comprising the primary key.
Unique Key:- A unique key is a key which stores unique values (no duplicates) for that particular column.
Difference between Primary Key & Unique Key:-
1. A Unique key can store a null value and primary key cannot store any null value.
2. A primary key can be references to another table as a Foreign Key.