GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  SQL Plus
Go To First  |  Previous Question  |  Next Question 
 SQL Plus  |  Question 123 of 132    Print  
What is the basic difference between primary key and (unique key along with Not NULL).

  
Total Answers and Comments: 11 Last Update: June 06, 2009     Asked by: globalanil18 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Sachin Agarwal
 
The difference is as follows:
1) Basically we define a column/multiple column's as primary key that represents the whole row, A unique key can be any.
2) Primary key are considered as Clustered Index for the table and as we can define only one clustered index for the table, the other columns can only be non-clustered index.
3) We can use primary key in where clause for updating a record as it represents that row which may not be true in case of unique key. Even if the key is unique the table might have a composite key as a primary key.
4) A primary key can act as a foreign key for other related tables, a unique key cannot.
5) The data in a row is dependent on a primary key whereas it may not be for the unique key.

This is all that i know about it. Others can also add some more things to it.

Above answer was rated as good by the following members:
Mohamed Harish
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
March 29, 2007 16:27:02   #1  
Ritesh Raj Singh        

RE: What is the basic difference between primary key a...

Hi


Basic Diffrence between primary key and unique key is the capability of unique key

for storing null values a primary key on a column gurantees that the column must contain a value for a given row but a unique key only guarantees that a column should be unique.


Apart from this difference in oracle unique and primary key creates difference in

performance

e.g : a primary key on a table enhance capability of using index

on select count(*) from table_name only if the table is analyzed

but a unique key won't


 
Is this answer useful? Yes | No
March 31, 2007 03:00:53   #2  
globalanil18 Member Since: August 2006   Contribution: 19    

RE: What is the basic difference between primary key a...

Hi Guys

Thanks for reply. But my Qn has not answered yet.

My Qn was

What is the basic difference between primary key and (unique key along with Not NULL).

If we define a unique key as not null then it also take a unique value as well as not null value that means one can not insert Null value in that column.

Thanks


 
Is this answer useful? Yes | No
April 03, 2007 15:21:23   #3  
ggk.krishna Member Since: February 2007   Contribution: 12    

RE: What is the basic difference between primary key a...

Hi Anil
Apart from NOTNULL I can tell you one more difference.

We can define Primary key on only one column in a table.
But for Unique key there is no limit. we can define as many columns as we want.

 
Is this answer useful? Yes | No
April 05, 2007 00:55:23   #4  
globalanil18 Member Since: August 2006   Contribution: 19    

RE: What is the basic difference between primary key a...

Hi!

Thanks for reply.

But why we define primary key. while we can use the same feature by define unique key along with not null.

Anil

 
Is this answer useful? Yes | No
April 14, 2007 06:41:35   #5  
Maria        

RE: What is the basic difference between primary key a...
primary key unique + not null + the only one PK column in the table + index on the PK column Created index enchances the queries on the PK column.
 
Is this answer useful? Yes | No
September 23, 2007 14:40:33   #6  
glakshkar Member Since: September 2007   Contribution: 5    

RE: What is the basic difference between primary key a...

Hi Anil
Apart from NOTNULL I can tell you one more difference.

We can define Primary key on only one column in a table.
But for Unique key there is no limit. we can define as many columns as we want.

THis is totally wrong Primary key too can contain multiple column.

Dear Anil

we can achieve PK functionality via using Unique key+ Not Null contsraint

but it's not gud practice when u can achieve same functionality via single PK constraint



 
Is this answer useful? Yes | No
September 23, 2007 16:07:30   #7  
Dumpo        

RE: What is the basic difference between primary key a...
It is also required to create a referential integrity (foreign key) constraint.
 
Is this answer useful? Yes | No
January 16, 2008 06:07:52   #8  
Sachin Agarwal Member Since: January 2008   Contribution: 1    

RE: What is the basic difference between primary key and (unique key along with Not NULL).
The difference is as follows:
1) Basically we define a column/multiple column's as primary key that represents the whole row A unique key can be any.
2) Primary key are considered as Clustered Index for the table and as we can define only one clustered index for the table the other columns can only be non-clustered index.
3) We can use primary key in where clause for updating a record as it represents that row which may not be true in case of unique key. Even if the key is unique the table might have a composite key as a primary key.
4) A primary key can act as a foreign key for other related tables a unique key cannot.
5) The data in a row is dependent on a primary key whereas it may not be for the unique key.

This is all that i know about it. Others can also add some more things to it.

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
May 15, 2008 11:13:38   #9  
ramesh_bollapragada Member Since: May 2008   Contribution: 1    

RE: What is the basic difference between primary key and (unique key along with Not NULL).
hi every one

differences

1) primary key is defined only on one column where as unique + not null can be defined on many columns

2) we can define the relationship ( master detail relationship) with references to unique+not null column but it is not possible to remove the relationship with

alter table <tablename> primary key cascade. Because Unique + Not null is not exactly primary key

3) When you refer the data dictionery with unique and not null it is going to create to different constraints where as with primary key it is going to create one constraint.


Regards

Ramesh B

 
Is this answer useful? Yes | No
July 23, 2008 03:13:20   #10  
mohanban Member Since: July 2008   Contribution: 2    

RE: What is the basic difference between primary key and (unique key along with Not NULL).
In addition to all this unique key along with Not NULL constraint has got a name i.e. candidate key .So a table having a column which is unique as well as not null apart from primar key is known as a candidate key.Thanks...
 
Is this answer useful? Yes | No
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape