Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all,
Can any one explain me with examples whats the difference between a primary key and a unique key.
Thanks in advance
Ranjit
Ranjit,
From what I understand, a primery key is a unique key that has to be defined at the moment of creation for each row like EmployeeID in a table of Employees where the values are probably consecutive, and a unique key is a column that has unique values like Social Security Number and can be used to identify an employee, but is not required information at the moment of creation.
Regards.
Hello All,
Primary Key and Unique Key are both same and used as a unique identifiers.
only difference is that a primary key can not have a null value but the unique key can have that too only once.
Also you can have more than one UNIQUE constraint per table but in case of primary key
Primary Key: A column in a table whose values uniquely identify the rows in the table. A primary key value cannot be NULL.
Unique Key: Unique Keys are used to uniquely identify each row in a table. There can be one and only one row for each unique key value.
Thanks Karl, I got an idea about the topic.
Hi
Normal 0 false false false EN-US X-NONE X-NONE
Difference between Primary key and Unique key:
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.
Primary key is only one constraint per table and also unique also only one per table.
The main difference between primary key and unique key is primary key doesnot allow duplicate values where as uniques will allow one duplicate values(Sql server 2005 & 2008).
In Oracle Unique allows n no of null values. Becaue null!=null.