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

Can a table have more then one primary key


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

New User


Joined: 29 Sep 2004
Posts: 35
Location: bangalore

PostPosted: Wed Oct 20, 2004 8:28 pm
Reply with quote

q1. Can a table have more then one primary key.

q2
. What is the diff. between unique key and primary key.

q3. is it necessary to creat a index for every table.

q4.Can a table resides under more then one tablespace .
Back to top
View user's profile Send private message
janardhana Reddy

New User


Joined: 20 Oct 2004
Posts: 17
Location: Bangalore

PostPosted: Thu Oct 21, 2004 3:36 pm
Reply with quote

Hi

1) Ans. One table should have only one primary key.
2) Ans. The main difference b/t unique key and primary key is null value.
Unique key may have null value.
3) Ans. If no index exists means you will not able execute some functions like count etc. To create path you need the index. If no index means there is no difference between flat file and database file..

4) no table can reside in more than one table space.
Back to top
View user's profile Send private message
khamarutheen

Active Member


Joined: 23 Aug 2005
Posts: 677
Location: NJ

PostPosted: Wed Nov 23, 2005 2:36 pm
Reply with quote

hi frnd,
one more thing is that unique key will have only one null value i think so.
but primary key will not have that too.

and if the primary key is created then u should need the unique index such that to activate the primary key.
Back to top
View user's profile Send private message
priya

Moderator


Joined: 24 Jul 2003
Posts: 568
Location: Bangalore

PostPosted: Wed Nov 23, 2005 2:55 pm
Reply with quote

Yes, you can have more than one columns as primary key. It's called as partial key.
Back to top
View user's profile Send private message
jontyjun

New User


Joined: 12 Sep 2006
Posts: 12
Location: India

PostPosted: Tue Aug 21, 2007 4:33 pm
Reply with quote

Hi Janardhana Reddy,

This is in regard to your answer: "3) Ans. If no index exists means you will not able execute some functions like count etc. To create path you need the index. If no index means there is no difference between flat file and database file.."

For Count You dont need an index at all... Verified it just now..

Regards,
Arjun.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Tue Aug 21, 2007 5:29 pm
Reply with quote

1) No - as has been stated but a primary key can be multiple columns
If you define a primary key with multiple columns, when you reference only one of those columns it is called a partial key

2) Primary key should be defined as the most commonly accessed key
Unique keys are ususually defined on columns other than the primary key. Think of them as alternate indexes on a VSAM with a uniqueness contraint. Although I have never heard them called Unique keys, usually they are called indexes.
3) No - but it will help performance
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 Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top