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 default values

Creating default values - SQL Server Tutorial

From the course: SQL Server 2008 Essential Training

Start my 1-month free trial

Creating default values

When you're designing databases, it's a good idea to apply as many rules or constraints to your data as possible. And one of the classic ways to do this is by setting up default values for your columns. The idea of this of course is simple. We have a table such as an OrderItem table made of product IDs and quantities and unit prices. Whereas a lot of this information is very different from row to row, Quantity for example might typically be the number 1. Occasionally it might be 2, but nine times out of ten or nineteen times out of twenty or ninety-nine out of a hundred it will be the number 1. So we will make this the default value for that column, so it doesn't always have to be entered, either by the application or by the user. I'm going to go into my OrderItem table in SQL Server Management Studio and select Design. Applying a default value is very simple. Find the column that you're looking for, in this case Quantity, and then down here in the Column Property section, you'll find…

Contents