Viewers: in countries Watching now:
In SQL Server 2008 Essential Training, Simon Allardice explores all the major features of SQL Server 2008 R2, beginning with core concepts: installing, planning, and building a first database. Explore how Transact-SQL is used to retrieve, update, and insert information, and gain insight into how to effectively administer databases. The course also covers features outside SQL Server's database engine, including technologies that have grown up around it: SQL Server Reporting Services and Integration Services. Exercise files are included with the course.
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. What we need to type in is an expression. In this case, it's quite simple. Quantity > 0 AND Quantity < 51. Close.
We now have a check constraint defined on the table. It is considered a table change. So I see the asterisk. I have got to save that. Close this down. Now, when I go into that table and I say change one of the existing rows, 50 is accepted as a change and I can click off that row. 51 will actually throw an error here. The update statement conflicted with the check constraint. I also can't put a 0 Quantity and I can't put a negative Quantity.
Check constraints can easily be removed. I need to escape out of here before it tries to apply those changes. I could go back into the Design view, again right-clicking anywhere in the Designer, because the check constraints are defined for the table. They're not defined specifically on a column. It's just this expression. You could have one check constraint that has multiple columns in it. Quantity above a certain amount if ProductID in a particular range. But if we wanted to, we could just come in here and hit the Delete button to remove the check constraint from the table, but I'm going to keep it.
Find answers to the most frequently asked questions about SQL Server 2008 Essential Training .
Here are the FAQs that matched your search "" :
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.