From the course: SQL Server 2008 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Creating check constraints

Creating check constraints - SQL Server Tutorial

From the course: SQL Server 2008 Essential Training

Start my 1-month free trial

Creating check constraints

Another way that we can increase the reliability, the integrity of our data, is to apply what are called check constraints. A check constraint is a simple idea. If we have some data such as Quantity where we can look at that and understand this really unacceptable range for this to be in, even though this column is actually being defined as an int, we don't need all that an int can give us. Because an integer can support from roughly -2 billion to plus 2 billion, it is quite unlikely that someone will order -2 billion quantities of a unit. So let's say I want to enforce some rules on this column that says Quantity must be greater than 0 and less than 51 say. Well, I do this by applying a check constraint to the table. I am going to right-click anywhere in the Designer area. It really doesn't matter. And I have a section called Check Constraints. Right now it's saying there are no check constraints on this table. I am going to add one. It's typically called CK_ the name of the table…

Contents