This topic describes how to define constraints on object
identifier columns.
About this task
If you want to use the object identifier column as a
key column of the parent table in a foreign key, you must first alter
the typed table to add an explicit unique or primary key constraint
on the object identifier column. For example, assume that you want
to create a self-referencing relationship on employees in which the
manager of each employee must always exist as an employee in the employee
table, as shown in Figure 1. Figure 1. Self-referencing type
example
To define constraints on an object identifier column
to create a self-referencing relationship on an object:
Procedure
Create the type, for example:
CREATE TYPE Empl_t AS
(Name VARCHAR(10), Mgr REF(Empl_t))
MODE DB2SQL;
Create the typed table, for example:
CREATE TABLE Empl OF Empl_t
(REF IS Oid USER GENERATED);
Add the primary or unique constraint on the Oid column,
for example: