Page 1 of 1

Composite primary key

Posted: Mon Apr 02, 2007 9:20 am
by via
Hi,
Can a column in a composite primary key be a null? we have a primary key with combination of 2 key columns.In those 2 key columns , can anyone be null?
Database is DB29.Does it accept? Any ideas.

Thanks

Posted: Mon Apr 02, 2007 9:21 am
by ray.wurlod
No.

Posted: Mon Apr 02, 2007 9:22 am
by ray.wurlod
No.

(having some transmission difficulties here - moderator, please remove)

Posted: Mon Apr 02, 2007 9:23 am
by ray.wurlod
All primary key columns in DB2 tables must be NOT NULL.

Re-design the target table. Or use a dedicated default value.

What does it really mean that you want to make part of a key unknown? Ponder on that for a while.

Posted: Mon Apr 02, 2007 9:31 am
by via
Thanks Ray..

Posted: Mon Apr 02, 2007 10:46 am
by via
Hi,
I got small doubt.If a key is specified on a column, Does it mean that it is indexed as a default? And if we create index on a column, does it mean that its a key?
I appreciate any clarifications..
Thanks

Posted: Mon Apr 02, 2007 10:51 am
by DSguru2B
No. But usually indices are created on keys for faster updates and retrievals.

The vice versa is also not important, i.e, if an index is set on a column, it does'nt mean it is a key.

Posted: Mon Apr 02, 2007 10:59 am
by via
Thanks Brian..But i want to know as key is created on a column, is it indexed as well? or should we explicitly create an index on that key column.

Thanks

Posted: Mon Apr 02, 2007 11:00 am
by DSguru2B
Indices need to be created explicitly, so yes, create them explicitly.

Posted: Mon Apr 02, 2007 11:04 am
by via
Thanks for the clarification..Really this DSXchange is helping a lot..

Posted: Mon Apr 02, 2007 11:45 am
by ray.wurlod
Note that the answer given relates to DB2. Some databases do automatically create an index on the primary key (though not on its individual columns).

Posted: Tue Apr 03, 2007 3:28 pm
by via
Thanks Ray for pointing that..