Difference between primary key and unique key ?
Answers were Sorted based on User's Feedback
Answer / alok
There is only two Point:
1. The not null constraint is by default added to primary key, it means, primary key attribute cannot accept null values, whereas, the attribute declared as unique can accept null values. It is the major difference between the two.
2. Secondly, we can have only one primary key in a relation, whereas, multiple attributes can be declared unique at the same time.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / yjreddy
primary key doesnt allow duplicates and null values
unique key allows null value only once
and more over
when you applying primary key by default clustered index is created on that table
when u applying unique key non clustered index is created on that table.
so primary key can be allowed only once(1) and unique u can apply more
than one on a single table(249)
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / madhumita majhi
In SQL both primary key and unique enforce uniqueness of
the column on which they are defined. But by default
primary key creates a clustered index on the column, where
are unique creates a non-clustered index by default.
Another major difference is that, primary key doesn't allow
NULLs, but unique key allows one NULL only.
Unique Key: Identify the row by uniquely, means if you are
inserting a records into the table suppose you already
inserted a record with ID 101 and another record you are
inserting with the same ID then it will give an error
(unique key voilation).
Prmary Key:Once you define a primay key on a particular
column then a column become a mandatory field.That means
you need to insert something on it, you can not leave as a
blank otherwise it will give an error as primary key
voilation.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / rakesh dwivedi
1.Primary key can not have null.Instead of it unique can have null at lest single time null.
2 In a table only one primary key exist.Unique can be multiple in table.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / rubiya george
Primary Key Vs Unique key
1.Each table having 1. contain many UNIQUE KEYS.
only one PRIMARY KEY.
2.Primary key not accepts 2.Unique Key accepts null
null values values
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / anand b
Primary Key : Is an identity of a row, Only one primary key per table, No duplicate values allowed, & No NULL values are allowed.
Unique Key : Its values are unique, It can contain any number of NULL values unless combination is going to be unique.
Is This Answer Correct ? | 1 Yes | 2 No |
Answer / sonali.s
column having primary key constraint should not contain
null values.
column having unique key constraint can contain null values.
Is This Answer Correct ? | 1 Yes | 2 No |
-The column holding the primary key constraint cannot accept
null values.whereas colum holding the unique constraint can
accept null values.
-We can declare only one primary key in a table
but a table can have multiple unique key
-Clustered index is created on Primary key constraint and
non clustered unique indexes is created on Unique key constraint.
-Primary key columns automatically become NOT NULL (unique
keys can contain nulls).
Is This Answer Correct ? | 1 Yes | 2 No |
Answer / chintan desai
Primary key don't have any null value, each table have only
one primary key. Not support duplicate value.
Unique key is uniquely identify, more then one unique key
allow in table.
Here the main different is what primary key do not have any
null value where unique key have only one null value.
Ex: here t1 is the name of table which have two field id and
name. here id is identify as a unique key then unique key's
null value look like under bellow:
1 chintan
NULL komal
2 ck
NULL NULL
Is This Answer Correct ? | 2 Yes | 3 No |
Answer / mudigouda patil
PRIMARY KEY
1)TABLE CAN NOT HAVE MORE THAN ONE PRIMARY KEY.
2)PK DOES NOT ALLOW NULL VALUES.
UNIQUE KEY
1)TABLES CAN HAVE MORE THAN ONE UNIQUE KEY.
2)UNIQUE KEY ALLOWS NULL VALUES.
Is This Answer Correct ? | 0 Yes | 1 No |
How to omit columns with default values in insert statement in oracle?
I just want to maintain data like an employee can belongs to 3 or more departments . We can resolve this by using composite key but it avoids normalization rules. So Can anyone tell me how can I maintain data.
Define oracle database
Will you be able to store pictures in the database?
what are Triggers?
What is the usage of analyze command in oracle?
What is the difference between normal and corelated subqueries?
Display those managers salary greater than the average salary of his employees?(Based on oracle standard Emp table)
How to define an anonymous procedure with variables?
find the second highest salary of the emp table
What is a trigger and what are its types?
What are temporal data types in oracle?