Primary and Unique Keys

DB2 PRIMARY KEYS are declared at the end of the DB2 table definition when primary indexes are defined in the associated Access table. All columns comprising the primary key include the NOT NULL constraint as required by DB2. Although the Access “Required” property does not need to be explicitly set, the not null constraint is implicit for all fields comprising Access primary keys. Any descending order properties specified for Access primary key fields are ignored since DB2 does not recognize descending order columns in primary keys.

 

DB2 UNIQUE KEYS are declared at the end of the DB2 table definition when the corresponding Access unique index does not specify descending order, otherwise, a DB2 CREATE UNIQUE INDEX statement is issued that includes descending order columns. If any Access field comprising a unique index has the “Required” property set to “No”, a non-unique CREATE INDEX statement is issued and the uniqueness constraint is implemented using triggers since DB2 does not allow duplicate nulls in unique indexes1.

 

The MS-Access REQUIRED property defaults to No. You must set the REQUIRED property to Yes when specifying unique indexes in order to generate DB2 unique indexes that prohibit duplicate null index values.

 

Important: Tables are not updatable using ODBC unless a unique index is defined for the table. Assigning a primary key also satisfies this constraint.

 

Note1: DB2 for OS/390 supports nulls in unique indexes by specifying “WHERE NOT NULL” after the word “UNIQUE” in the index statement.