Page 1 of 1

What is the difference between setting the primary key and creating an index?

Posted: Sat Nov 14, 2015 1:09 pm
by Abhay Gadkari
HI All

Can anyone please help me in knowing e difference between setting the primary key and creating an index for a DB2 table? Why should we set the primary key as not NULL always?


Thanks in advance!

Re: What is the difference between setting the primary key and creating an index?

Posted: Sat Nov 14, 2015 7:08 pm
by nicc
How would you find your record if it does not have a key?

Re: What is the difference between setting the primary key and creating an index?

Posted: Sat Nov 14, 2015 8:21 pm
by Robert Sample
A primary key SHOULD provide a unique record reference for every record in the table. If you have records with a NULL primary key, how would you find each one uniquely? An index is an access path to the table -- it may have duplicates (and many of them) which is fine since you usually won't care which record with index value 30052 you get first or second or thirty-ninth. Each record retrieved via the index, however, had better have a unique primary key!