Constraint Editor

Previous  Index  Next  How To Use

There are four types of constraints:


Primary Key Constraints
Unique Constraints
Foreign Key Constraints (also called Referential Constraints)
Check Constraints


All these types of constraints can be created, altered and dropped from the Constraint Editor. In order to support this, the layout of the Constraint Editor is slightly different compared to the other editors. The New Constraint button has a small arrow added that, when clicked, shows a menu. Clicking the button without using the arrow shows a selection dialog in order to select the constraint type to create.


Constraint Editor - constraint type menu


For tables that already have an existing primary key constraint, the Primary Key menu item is disabled. After you have selected a constraint type, the constraint editor will show it's corresponding editor type and you can create your constraint.


Primary and Unique Constraints

Basically, a Primary Key Constraint is an Unique Constraint except that there can only exist one per table. In general, both will have a "left-right" list of columns that show what columns are available and what columns are in the constraint. Columns that exist, but aren't suitable to be included in the constraint are colored light-gray. InterBase, for example, doesn't allow NULLable columns in an Unique Constraint.


Double clicking or using the arrow keys adds/removes the column from the constraint.


Primary and Unique Constraint "left-right" view


Foreign Key Constraints

A foreign key constraints are one or more columns that "point" to other columns. Because the "referred-to" columns need to be uniquely identifyable, you need a primary or unique constraint on these columns in order to be able to create a foreign key constraint. This is why Database Workbench doesn't let you select columns from a target table, but only constraints. This avoids errors and the need to select individual columns. Make sure to select "referring fields" in the right order.


Foreign Key Constraint - a "left-right" view and referred table constraint selection


Check Constraints

A check constraint can contain pieces of source code, and therefore uses syntax highlighting in it's editor - it also accepts columns and table names dragged from the Describe Companion and Database Navigator.


Check Constraint source editor