strings that have a predefined size—in such cases, it may be more efficient
to use the nchar(n) type than nvarchar.
money, money, money
Sometimes, you may see poorly designed databases use float to store monetary
data. As float is susceptible to rounding errors, this is a bad idea. money, on
the other hand, is not susceptible to these errors and is a much better choice.
The SQL Server data types, as with the other SQL Server keywords, aren’t case-
sensitive. nvarchar and nchar have non-Unicode cousins named varchar and char,
which you can use if you’re sure you won’t need to store Unicode data. You may
need to use Unicode (or a language-specific form of encoding) when storing non-
English text, such as Chinese, Arabic, and others. Unicode is a very widely sup-
ported standard, so it’s strongly recommended you stick with nvarchar and nchar.
The type of a column defines how that column behaves. For example, sorting
data by a datetime column will cause the records to be sorted chronologically,
rather than alphabetically or numerically.
Column Properties
Other than a column’s data type, we can define a number of other properties for
a column. Other properties you’ll use frequently include:
NULL
In database speak, NULL means “undefined.” Although we talk about it as if
it’s a value, NULL actually represents the lack of a value. If you set an employ-
ee’s mobile telephone number to NULL, for example, this could represent the
fact that the employee doesn’t have a mobile telephone.
However, it’s important to realize that allowing NULLs is often inappropriate.
For instance, you might create a department with the name NULL to represent
a mysterious department with no name, but obviously, this is far from ideal.
As you create a table, you can specify which columns are allowed to store
NULL, and which aren’t. In our example, we’d like every department to have
a name, so we shouldn’t allow the Name column to allow NULLs.
DEFAULT
SQL Server is capable of supplying a default value for a certain column if
you don’t supply one when you add a new row. We won’t be using this feature
when we create Dorknozzle, but it’s good to know you have this option.
264
Chapter 7: Database Design and Development