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

RDBMS from IBM and IBM's Hierarchical DBMS and Transaction Manager (IMS DC).
Post Reply
Abhay Gadkari
New Member
Posts: 2
Joined: Sat Aug 16, 2014 10:17 pm

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

Post 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!
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

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

Post by nicc »

How would you find your record if it does not have a key?
Regards
Nic
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

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

Post 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!
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM DB2 and IMS DB/DC”