Constraints are restrictions or limitations that you place on your database. Constraints are implemented at the table level. You can use constraints to create referential integrity in your database. In System i Navigator, you can add several types of constraints.
A key constraint is added to a column in a table to prevent duplicate information. In System i Navigator, you can add primary keys and unique keys. When primary keys are joined with a foreign key, they create a relationship between two tables called a referential constraint. A table can contain only one primary key, multiple unique keys, and multiple foreign keys.
A referential constraint creates a relationship between a dependent table and a parent table. The system guarantees that for each row in the dependent table with a non-null value in all of its foreign key columns, there is a row in the parent table with a matching value in its parent key. Once you have your business rule set up as a referential constraint, any program that attempts to insert, delete, or update a row can not violate that constraint. This relationship is established by creating key values between the two tables. These keys are called the parent key in the parent table and the foreign key in the dependent table. The parent key can be either a primary or a unique key.
A check constraint is created on a column to ensure that the value of that column conforms to a specified value or range of values established by your business rules. Whenever you insert or update a column with a check constraint, the check constraint validates the new data against the business rule and disallows any attempt to violate it
In System i Navigator, you can add a constraint to a new table or to an existing table. However, you may only modify the constraint if it has been defined during your current table editing session. If you want to change the definition of an existing constraint, you must drop the constraint and then recreate it with the appropriate changes.
You can do the following tasks with constraints:
For more information about constraints, see the following:
in the Information Center