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 - SQL Server Tutorial
From the course: SQL Server 2008 Essential Training
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
Planning your database9m 39s
-
(Locked)
Creating a SQL Server database4m 7s
-
(Locked)
Creating tables7m 50s
-
Data types in SQL Server12m 25s
-
(Locked)
Defining keys8m 9s
-
(Locked)
Creating default values4m 39s
-
(Locked)
Creating check constraints2m 25s
-
(Locked)
Creating unique constraints4m 34s
-
Introduction to relationships and foreign keys9m 51s
-
(Locked)
Creating relationships in SQL Server Management Studio8m 14s
-
(Locked)
Database normalization11m 47s
-
(Locked)
Creating computed columns3m 10s
-
-
-
-
-
-
-
-
-
-
-
-