From the course: SQL Server 2014: Developing Databases

Unlock the full course today

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

Implementing check constraints

Implementing check constraints - SQL Server Tutorial

From the course: SQL Server 2014: Developing Databases

Start my 1-month free trial

Implementing check constraints

- Now, we're going to take a look at the concept of a check constraint. Now, a check constraint enforces certain rules onto either the entire table or into a certain column. When I say the entire table, you can setup, say in our classroom if we were looking at the individual classrooms and it had a capacity of 20 students, then we could setup a check constraint so that we wouldn't exceed more than 20 students at any one time. As far as the practicality of that in a classroom, I don't like it because what if you moved the chairs around or combines classrooms, et cetera. So, that's probably not a very good way to solve that problem, which, by the way, is beyond the scope of what we're doing here initially. It's something you might want to noodle as you're thinking through this on your own and see how you would solve that problem. A good use, perhaps, of a check constraint is to set one up to say, we have a level, I was thinking here about the course table we have, and we setup columns…

Contents