Home » SQL & PL/SQL » SQL & PL/SQL » Difference between Primary key and Unique key  () 1 Vote
Difference between Primary key and Unique key [message #198468] Tue, 17 October 2006 04:58 Go to next message
kirankumartata12
Messages: 2
Registered: October 2006
Location: India
Junior Member
Dear Friends,

Can i know what are all the differences between the primary key and unique key.

Thanks to all
Re: Difference between Primary key and Unique key [message #198475 is a reply to message #198468] Tue, 17 October 2006 05:21 Go to previous messageGo to next message
lecorr
Messages: 17
Registered: October 2006
Location: Courbevoie, France
Junior Member
Primary CAN NOT be NULL

Unique can be Null.

Primary is use to be sure to get at least one and only one record when a select .. where PK=x is done.

Unique will return at most one (and possibly 0) rows.

PK can be used for foreign keys, unique can not.

[Updated on: Tue, 17 October 2006 05:22]

Report message to a moderator

icon7.gif  Re: Difference between Primary key and Unique key [message #198478 is a reply to message #198468] Tue, 17 October 2006 05:44 Go to previous messageGo to next message
aditiC
Messages: 38
Registered: February 2006
Location: INDIA
Member
Hi Kiran,

Reg diference between primary & unique key,

a primary key cannot have null values but a unique key can have null values.

Also, a table can have only 1 promary key constraints(composite primary key) but unique key constraints can be more than once.
Re: Difference between Primary key and Unique key [message #198479 is a reply to message #198475] Tue, 17 October 2006 05:53 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
lecorr wrote on Tue, 17 October 2006 12:21
Primary is use to be sure to get at least one and only one record when a select .. where PK=x is done.


huh? Do you mean that for every value of x a row is returned???

lecorr wrote on Tue, 17 October 2006 12:21
PK can be used for foreign keys, unique can not.


Not true. Unique keys can also be referenced to by foreign keys
Re: Difference between Primary key and Unique key [message #198490 is a reply to message #198479] Tue, 17 October 2006 06:38 Go to previous messageGo to next message
lecorr
Messages: 17
Registered: October 2006
Location: Courbevoie, France
Junior Member
Sorry for errors, you are right...

I was a bit fast befor lunch...
Re: Difference between Primary key and Unique key [message #198509 is a reply to message #198490] Tue, 17 October 2006 07:43 Go to previous messageGo to next message
rleishman
Messages: 3724
Registered: October 2005
Location: Melbourne, Australia
Senior Member
A primary key can be used to fast refresh a dependent MV, Unique cannot.

Ross Leishman
Re: Difference between Primary key and Unique key [message #198524 is a reply to message #198475] Tue, 17 October 2006 08:56 Go to previous messageGo to next message
kirankumartata12
Messages: 2
Registered: October 2006
Location: India
Junior Member
Dear Friend,

I did not understand what it really means.

Primary is use to be sure to get at least one and only one record when a select .. where PK=x is done

A primary key can be used to fast refresh a dependent MV, Unique cannot.

Can you give me some explanation

Thanks
Re: Difference between Primary key and Unique key [message #198528 is a reply to message #198524] Tue, 17 October 2006 09:08 Go to previous message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
link 1
link 2

MHE
Previous Topic: ORA-00036: maximum number of recursive SQL levels (50) exceeded
Next Topic: Web page redirect
Goto Forum:
  


Current Time: Sat Dec 03 22:02:37 CST 2016

Total time taken to generate the page: 0.11461 seconds