Hello there;

I have been trying to understand how contraints work, and how to apply them to my code, however, I just can't seem to grasp exactly how they work. Would it be possible for get some general info on HOW contraints work, and HOW to apply them to your code. in some of the examples I've seen, they have these constraints included, but everywhere I look, there's hardly any specific info on HOW to use these constraints.

Any help in clearing this fog in my mind about how to use these would be appreciated.


Hi dakoris73

A constraint is kind of restriction usually to the range of values of a variable.
Given the following create-table statement we can detect several constraints:

create table raint(id integer UNIQUE, NOT NULL,
day char(10) CHECK(day IN ('Monday', 'Tuesday', 'wednesday', . . .) );

This constraint assures that column id cannot contain duplicate values.

This constraint requires that every insert-into statement of table raint
must also insert a value in column id not equal to NULL (NULL "value" indicates
that a column does not have a value stored)

This is a rather new and some more powerful constraint introduced with the SQL 1999 standard. Above is a mere simple example of a possible application.

Much more powerful constraints can be programmed by using the trigger concept
for what SQL standard has its own programming language (PSM).

I hope my annotations will create some clarification.