View previous topic :: View next topic |
Author |
Message |
NASCAR9 Intermediate
Joined: 08 Oct 2004 Posts: 274 Topics: 52 Location: California
|
Posted: Thu Nov 17, 2005 4:45 pm Post subject: Primary Key Vs Unique Index |
|
|
Is there any performance or less overhead to be gained by defining a table with PRIMARY KEY vs. just creating a UNIQUE INDEX?
Code: | CREATE TABLE HOURS.A2BKCNT
(SSNO INTEGER NOT NULL,
WRKPERIOD DATE NOT NULL,
A2COUNT SMALLINT NOT NULL,
MEMTYPE CHAR(2) NOT NULL,
OLDESTHRS DATE NOT NULL,
PARDTHRS DATE NOT NULL,
PARELG DATE NOT NULL,
DEPDTHRS DATE NOT NULL,
DEPELG DATE NOT NULL,
LASTUPDT TIMESTAMP NOT NULL,
USERID CHAR(40) NOT NULL,
PRIMARY KEY (SSNO))
IN FDBHRS.FTSA2CNT
;
CREATE UNIQUE INDEX HOURS.XELG2CNT
ON HOURS.A2BKCNT
(SSNO)
USING STOGROUP FSGALLP
PRIQTY 5000
SECQTY 1000
CLUSTER
BUFFERPOOL BP5
COPY YES
CLOSE NO;
VS
CREATE TABLE HOURS.A2BKCNT
(SSNO INTEGER NOT NULL,
WRKPERIOD DATE NOT NULL,
A2COUNT SMALLINT NOT NULL,
MEMTYPE CHAR(2) NOT NULL,
OLDESTHRS DATE NOT NULL,
PARDTHRS DATE NOT NULL,
PARELG DATE NOT NULL,
DEPDTHRS DATE NOT NULL,
DEPELG DATE NOT NULL,
LASTUPDT TIMESTAMP NOT NULL,
USERID CHAR(40) NOT NULL )
IN FDBHRS.FTSA2CNT
;
CREATE UNIQUE INDEX HOURS.XELG2CNT
ON HOURS.A2BKCNT
(SSNO)
USING STOGROUP FSGALLP
PRIQTY 5000
SECQTY 1000
CLUSTER
BUFFERPOOL BP5
COPY YES
CLOSE NO;
|
_________________ Thanks,
NASCAR9 |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Thu Nov 17, 2005 5:35 pm Post subject: |
|
|
NASCAR9,
When you create a table with PRIMARY KEY , it's definition is incomplete until the primary index is created. Actually the Table is unavailable until the index is created.
Defining a column has advantages that it is a unique key and it cannot contain NULLS.
You can achieve the same concept by defining the column as not null and creating an Unique Index on it.
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
NASCAR9 Intermediate
Joined: 08 Oct 2004 Posts: 274 Topics: 52 Location: California
|
Posted: Thu Nov 17, 2005 5:48 pm Post subject: |
|
|
Thanks kolusu,
This is what I suspected. I'm in the process creating many new tables.
I want to make sure they are defined in the most efficient way possible. Some of the questions I ask may seem obvious to many on this board, but keep in mind we are a very young DB2 shop. (Less than 6 years) _________________ Thanks,
NASCAR9 |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Thu Nov 17, 2005 6:22 pm Post subject: |
|
|
Quote: |
Some of the questions I ask may seem obvious to many on this board, but keep in mind we are a very young DB2 shop. (Less than 6 years)
|
Just add 2 more years to it and you have my experience ! Every question has its own merit. so Don't worry about it _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
Dip Beginner
Joined: 24 Mar 2006 Posts: 27 Topics: 14
|
Posted: Thu Jan 07, 2010 3:51 am Post subject: |
|
|
Can we define an Unique INDEX on two fields/keys where one of them can be NULL?
Thanks!
Dip. |
|
Back to top |
|
 |
Dip Beginner
Joined: 24 Mar 2006 Posts: 27 Topics: 14
|
Posted: Thu Jan 07, 2010 4:10 am Post subject: |
|
|
Just now i read in a discussion forum that DB2 has no problem or restriction with NULLs in non primary key-index. Can someone confirm it?
Also want to know, if there will be any performace degradation if 5% of the total records having NULL in one of the key field which is part of the Unique index?
Thanks!
Dip. |
|
Back to top |
|
 |
|
|