IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

PRIMARY KEY, UNIQUE constraint & UNIQUE INDEX


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
umeshkmrsh

New User


Joined: 21 Sep 2005
Posts: 79
Location: India

PostPosted: Wed Apr 05, 2006 2:05 pm
Reply with quote

PRIMARY KEY, UNIQUE constraint & UNIQUE INDEX

I have doubts regarding above three constraints in DB2, you all are requested to help me in clarifying my doubt. I am describing below my understanding of the above constraints. If you feel I am wrong please correct me giving proper reason.
NOTE: Please reply only if you are 100% sure. Also I am taking about DB2 and not about any other relational database).

Primary Key: Cannot have NULL values and the values must be unique.
Primary Key = Unique Constraint + NOT NULL constraint.

UNIQUE: Values in column should be unique, but only one NULL value is allowed. We cannot have multiple NULL values in a column having UNIQUE constraint.

UNIQUE INDEX: Values in the column must be unique, but with exception ? that we can have multiple NULL values. I doubt it?

But it's sure that all these three are different.
Back to top
View user's profile Send private message
perez_a

New User


Joined: 02 Feb 2006
Posts: 25
Location: Italy

PostPosted: Wed Apr 05, 2006 3:17 pm
Reply with quote

Hi umeshkmrsh ,
when u define an unique index, it can assume null value only 1 time.
Have a nice day perez_a
Back to top
View user's profile Send private message
umeshkmrsh

New User


Joined: 21 Sep 2005
Posts: 79
Location: India

PostPosted: Wed Apr 05, 2006 3:53 pm
Reply with quote

Hi perez_a,

Quote:
when u define an unique index, it can assume null value only 1 time.
Have a nice day perez_a


Then what's the difference between UNIQUE constraint and UNIQUE INDEX?? I know that UNIQUE constraint is internally handled using UNIQUE INDEX but they are different as far as NULL values are concerned.
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Wed Apr 05, 2006 5:18 pm
Reply with quote

Quote:
NOTE: Please reply only if you are 100% sure.

Then some body- has written manuals only- would have to come answering you. So why not you make a search yourself.
Pls try to avoid such remarks..its a discussion forum...not a Pay n Ask Shop

Quote:
what's the difference between UNIQUE constraint and UNIQUE INDEX??

Check this link...

Regards,
Priyesh.
Back to top
View user's profile Send private message
umeshkmrsh

New User


Joined: 21 Sep 2005
Posts: 79
Location: India

PostPosted: Wed Apr 05, 2006 6:05 pm
Reply with quote

Actually I was reading a manula and I got confused.

Quote:
Although a unique, system-required index is used to enforce a unique constraint, there is a distinction between defining a unique constraint and creating a unique index. Even though both enforce uniqueness, a unique index allows nullable columns and generally cannot be used in a referential constraint (the value "NULL" means a field's value is undefined and distinct from any other value, including other NULL values) while a unique constraint does not.


?[/quote]
Back to top
View user's profile Send private message
srini_igsi
Currently Banned

New User


Joined: 09 Dec 2005
Posts: 30
Location: Pune

PostPosted: Tue Aug 01, 2006 4:19 pm
Reply with quote

Hi,

which cataloged table can be queried to know the Primary Key or Unique Key defined over a table?
Back to top
View user's profile Send private message
chiranjeevi_mca

New User


Joined: 19 Feb 2006
Posts: 27

PostPosted: Tue Aug 01, 2006 5:33 pm
Reply with quote

sysibm.sysconstraints is used to view all the constrains of all the tables
Back to top
View user's profile Send private message
srini_igsi
Currently Banned

New User


Joined: 09 Dec 2005
Posts: 30
Location: Pune

PostPosted: Tue Aug 01, 2006 5:47 pm
Reply with quote

It is saying that the Table couldn't be found.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Cobol file using index COBOL Programming 2
No new posts Cobol prog to put an indicator on the... JCL & VSAM 1
No new posts DL/I status code AK for GU call using... IMS DB/DC 1
Search our Forums:

Back to Top