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.

Thanks,
Mikey

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', . . .) );

UNIQUE
This constraint assures that column id cannot contain duplicate values.

NOT NULL
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)

CHECK()
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.

krs,
tesu

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.