Quote:
|
Originally Posted by MarkhamDBA
do I have to have primary keys for this or it's enough to have unique index on these cols?
Thank you
|
Technically spoken DB2 can do without a Primary Key definition. Personally I do not accept tables without a PK definition.
Unique key - Wikipedia, the free encyclopedia
There is a catch with DB2: you can add the keywords "primary key" in the column defintion as part of the CREATE TABLE. DB2 will automaticly create an index for you. When you create you own index later (with unique/cluster/include parameters) you will have 2 almost-the-same indexes on that table causing only overhead and no gain what-so-ever.
So what they taught me:
- create table without the PK definition
- create the unique index (can be more columns)
- alter table to add the PK contraint
Now DB2 will check if there is already an index which can be used and will not create its own index. If you own index cannot be used, DB2 will create an index with the same name as you contraint.