What's the difference between a primary key and a unique key?
Answers were Sorted based on User's Feedback
Answer / raj
In primary key not allowed any null value while in unique
key one null value allowed.
| Is This Answer Correct ? | 22 Yes | 1 No |
Answer / srinivas
Primary key is a combination of unique+not null+cluster
index and it will not allow any duplicate values, null
values, and it's data will be arranged in ascending order
due to clustered index. Only one primary key is allowed
per table.
Unique key is a key which will not accept any duplicate
values, but it will accept one null value. We can place
any number of unique keys per table.
| Is This Answer Correct ? | 17 Yes | 0 No |
Answer / awdhesh
By default Primary Key Create Cluster index while unique
ker create non cluster index
| Is This Answer Correct ? | 17 Yes | 1 No |
Answer / sachin patil
only 1 p.K. have per table
u can have multipale Unique key per table
| Is This Answer Correct ? | 15 Yes | 4 No |
Answer / karthick
PRIMARY KEY AND UNIQUE KEY
* Both Enforces Uniqueness
* Primary key Creates clustered index
unique key creates non clustered index
* primay key does not allows null value
unique key allows 1 null value
| Is This Answer Correct ? | 10 Yes | 0 No |
Answer / karthikumar
The difference is primary key does not allow any one null
value,but unique allow only one null value,because it
consider null as one value
| Is This Answer Correct ? | 8 Yes | 1 No |
Answer / mrityunjay kumar
There are difference between Primary key and unique key.
1. Primary key allow not null value where as unique key
allow only one null value.
2. Primary key Creates clustered index where as unique key
creates non clustered index.
3. Primary key is only one in a table where as unique key
is multiple in a table.
4. Primary key is not accept duplicate value where as
Unique key is also not accept any duplicate values, but it
will accept one null value.
| Is This Answer Correct ? | 8 Yes | 1 No |
Answer / sunil
HI ALL
IN CASE OF INSERTING REPETED NULL IN UNIQUE KEY COLOUMN ,
IF IT IS COMPOSITE KEY IS POSSIBLE. . . ANY LOGICAL RESON?
Eg:
CREATE TABLE TRY(ROLL NUMBER,LIB_CARD_NO NUMBER,
CONSTRAINT CON_UNQ UNIQUE(ROLL,LIB_CARD_NO));
INSERT INTO TRY VALUES(NULL,NULL);
--> 1 ROW CREATED
INSERT INTO TRY VALUES(NULL,NULL);
--> 1 ROW CREATED -- REPETED NULL ARE ALLOWED!!!!
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / amit
-Both are Unique means they do not accept duplicate value.
-Primary key by default Clustered Index where as Unique Key
is a Non-Clustered Index.
-Primary Key does not accept null value where as Unique Key
accept only one Null Value.
-A table can have only one Primary Key where as A table can
have multiple Unique Key.
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / hameed
Primary key does not allow any null value in a table where
as Unique key allows only one null value
Primary key is by default a Clustered Index where as Unique
key is a non-clustered index
| Is This Answer Correct ? | 2 Yes | 0 No |
If suppose in a table ship(name,year),find ship name having first and last name(i.e having space in between) ex: SAINT LOUIS,JET LAKE.
What are the requirements to use odbc connections in php scripts?
What stored by the master?
How to copy the tables, schema and views from one sql server to another?
What is the disadvantage of using subquery exact after a select statement?ex. select (select * from sometable)
What are SSL and TSL protocols?
What is tcl in sql server?
Restore database SQL2000, SQL2012 Backup of base is created in Microsoft SQL Server 2000 - 8.00.2066, I can't restore on Microsoft SQL Server 2012 - 11.0.2100.60
What are the properties of the transaction?
How to find 6th highest salary from Employee table ?
What are the character string functions supported by sql server 2005?
Explain what is the difference between union and union all?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)