What is difference between UNIQUE and PRIMARY KEY constraints
Puran Mehra
Select an image from your device to upload
Unique key- unique key accept only one null value accept.but unique key use many time in table.
Primary key-Primary key does not accept null value and primary key use only one time in table.
Unique: unique it allows null value only once.
Primary key: It is unique but it does't allow null value.
You all are replying wrong.
unique key always allow more than one null value if you want. In oracle one null value never equals to another null values.
that is the difference between primary key and unique key.you cannot enter same as well as null values in primary key where as in unique key you cannot enter the same values but can enter more than one null value.
just make a table with unique key and check for yourself.
A table must contain only one primary key.if a table contains more than one primary key,then these are called composite keys.a primary key must be unique.but a unique key can't be a primary key.a table contains more than one unidue keys but a table must be identified by it's primary key.
Primary key:1)Primary key is nothing but it is uniqly identified each roe in Table.2)Primary key Does not Allowes Duplicate values and Null values.3)Primary key is default Clustered indexes4)One table can have only one Primary key.Unique Key:1)Unique Key is nothing but it is uniqly identified each roe in Table.2)Unique Key Does not Allowes Duplicate values but allowes only one Null value.3)Primary key is default Non- Clustered indexes
Regards,
Narasima
Both Primary and Unique Keys are enforce uniqueness of the column. But the differeces are given below:
Primary Key:
1) It creates clustered index by default
2) It doesn't allow nulls
Unique Key:
1) It creates non-clustered index by default
2) It allows only one null value
Regards
MadhuKumarKoppula
PRIMARY KEY ConstraintSpecifies the column that uniquely identifies a row in the table. The identified columns must be defined as NOT NULL.
Note: If you attempt to add a primary key using ALTER TABLE and any of the columns included in the primary key contain null values, an error will be generated and the primary key will not be added. See ALTER TABLE statement for more information.
UNIQUE KEY Constraint
Specifies that values in the column must be unique. NULL values are not allowed.Thanks!Manoj [InfoAxon Technologies Ltd.]
A table can have only one PRIMARY KEY whereas there can be any number of UNIQUE keys.
The columns that compose PK are automatically define NOT NULL, whereas a column that compose a UNIQUE is not automatically defined to be mandatory must also specify the column is NOT NULL.