SQLEditor Icon

Constraints

A constraint object represents a table or column constraint on the database.

SQLEditor supports UNIQUE and CHECK constraints.

UNIQUE Constraints

A UNIQUE constraint requires that the value in the specified column must be unique within the table.

If multiple columns are specified then each specific combination of values must be unique

For example, if the constraint was

UNIQUE(name,birthday,shoeSize)
then each row would have to have a different value for the the combination of name,birthday and shoe size.

row name birthday shoeSize
1 joe 01/01/1900 10
2 fred 01/01/1990 9

But the following row would be rejected if we tried to insert it.

row name birthday shoeSize
3 joe 01/01/1900 10

Because it has the same (name,birthday,shoeSize) combination as row 1

CHECK Constraint

A CHECK constraint specifies a particular expression that must be satisfied

An example might be that prices must be greater than zero. This would be expressed as follows:

CHECK(price > 0)

Any price value that wasn't above 0 would then be rejected by the database.

Support for constraints is database specific and some databases don't support CHECK constraints at all

Specifying Constraints

Constraints are edited using the inspector.

Table Level Constraints

Constraints at the table level use the constraint inspector panel.

Field Level Constraints

Use the Unique Checkbox in the field inspector

Use the Check Constraint subpanel of the field inspector


Related Topics