strings that have a predefined sizein 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, arent case-
sensitive. nvarchar and nchar have non-Unicode cousins named varchar and char,
which you can use if youre sure you wont 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 its 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 columns data type, we can define a number of other properties for
a column. Other properties youll use frequently include:
NULL
In database speak, NULL means undefined. Although we talk about it as if
its a value, NULL actually represents the lack of a value. If you set an employ-
ees mobile telephone number to NULL, for example, this could represent the
fact that the employee doesnt have a mobile telephone.
However, its 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 arent. In our example, wed like every department to have
a name, so we shouldnt allow the Name column to allow NULLs.
DEFAULT
SQL Server is capable of supplying a default value for a certain column if
you dont supply one when you add a new row. We wont be using this feature
when we create Dorknozzle, but its good to know you have this option.
264
Chapter 7: Database Design and Development

Get Build Your Own ASP.NET 2.0 Web Site Using C# & VB, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.