The constraints are used by DB2 Universal Database (TM) DB2 UDB to implement business rules on data. This article describes the following types of constraints: non-null not null), unique, primary key, foreign key, and table check. In addition, there is another constraint named informational constraint. Different from the five constraints listed above, information constraints are not implemented by the database manager, but can be used by the SQL Compiler to improve query performance. In this article, I will focus only on the constraints listed above, but will not discuss information constraints.
You can define one or more DB2 UDB constraints when creating a new table, or you can define them later by changing the table. The create table statement is very complex. Although only a small part of the options are used to define constraints, when you view the statements in syntax Diagrams 1 and 2, those options seem quite complex. The DB2 Control Center makes constraints management easier and easier.
Figure 1. Partial syntax of the create table statement, showing the clause used to define constraints
Constraint definitions are associated with the databases they are applied to and stored in table 1 in the database directory ). You can query the database directory to retrieve and view the information. You can directly create a database connection from the command line. Remember to first establish a database connection). Similarly, you will find it easier to access this information through the Control Center.
The created constraints can be processed like other database objects. They have names and associated mode creator IDS), and can be removed in some cases ).
Figure 2. Partial syntax of the create table statement, showing the continued clause used to define constraints)