Format CONSTRAINT constr-name [UNIQUE field-name, ... ] [PRIMARY KEY field-name, ... ] [FOREIGN KEY field-name, ... REFERENCES record-name field-name, ...] [CHECK (expression) ] [DEFERRABLE ] [NOT DEFERRABLE]
1 – Parameters
1.1 – constr-name
Specifies the name of the constraint.
1.2 – field-name
Specifies the name of the field to be used in a key or a field that is unique.
1.3 – record-name
Specifies the name of the record.
1.4 – expression
Specifies a Boolean expression. See Expressions for more information.
2 – Description
Use to specify a condition that affects adding or modifying data to the database table (CDO record). CDO provides syntax for record constraints, including specification of NOT NULL, PRIMARY KEY, FOREIGN KEY, UNIQUE, and CHECK (arbitrary search condition constraint) for fields and records.
3 – Examples
CDO> DEFINE RECORD PARTS cont> CONSTRAINT PARTS_PMK PRIMARY KEY PART_ID cont> CONSTRAINT PARTS_UNQ UNIQUE PART_NO cont> CONSTRAINT PART_CST CHECK cont> ANY P IN PARTS WITH (PART_ID IN PARTS = PART_ID_USED_IN IN PARTS) cont> CONSTRAINT PART_FRK cont> FOREIGN KEY PART_NO REFERENCES PARTS PART_ID. cont> PART_NO. cont> PART_ID. cont> PART_ID_USED_IN. cont> PART_QUANT. cont> END. CDO> SHOW RECORD PARTS/FULL Definition of record PARTS | Contains field PART_NO | | Datatype signed word | Contains field PART_ID | | Datatype signed longword | Contains field PART_ID_USED_IN | | Based on ID_DOM | | | Datatype signed longword | Contains field PART_QUANT | | Datatype signed word | Constraint PARTS_PMK primary key PART_ID NOT DEFERRABLE | Constraint PARTS_UNQ unique PART_NO NOT DEFERRABLE | Constraint PART_CST (ANY (P IN PARTS WITH (PART_ID IN PARTS EQ PART_ID_USED_IN IN PARTS))) NOT DEFERRABLE | Constraint PART_FRK foreign key PART_NO references PARTS PART_ID NOT DEFERRABLE This example uses the CDO DEFINE RECORD command syntax to establish constraints on the PARTS record. NOTE For the purposes of this example, it is assumed that the field definitions referred to in the record definitions have already been defined in the repository. This example assumes the PART_ID to be the primary key and the PART_NO to be a unique value across all possible parts. By not specifying whether the constraints are deferrable, the default evaluation time is accepted. In CDO, the default evaluation time for constraints is NOT DEFERRABLE. Constraints are evaluated at statement time. Using CDO, the record PARTS is defined with the following attributes: o Primary key PARTS_PMK o Unique constraint PARTS_UNQ o Check constraint PART_CST o Foreign key constraint PART_FRK