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!
What is the difference between setting the primary key and creating an index?
-
- New Member
- Posts: 2
- Joined: Sat Aug 16, 2014 10:17 pm
Re: What is the difference between setting the primary key and creating an index?
How would you find your record if it does not have a key?
Regards
Nic
Nic
- Robert Sample
- Global Moderator
- Posts: 1895
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: What is the difference between setting the primary key and creating an index?
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!
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