is a particular kind of constraint. When the primary key constraint is set on a
column, the database will refuse to store duplicate values in that column.
Constraints in general, and primary keys in particular, represent a means by
which the database can maintain the integrity and consistency of data.
Primary keys composed of a single column, such as Employee ID, are frequently
used in conjunction with the IDENTITY property. The primary key constraint
guarantees that duplicate values cannot be inserted into the table. The IDENTITY
property helps us by always generating a new value that hasn’t already been used
in the primary key.
Primary Keys and the IDENTITY Property
Using the IDENTITY property for a column doesn’t mean we can avoid
specifying a primary key. It’s true that the IDENTITY property always generates
unique values, but it doesn’t necessarily enforce them.
For example, say we have a table with a number of columns, one of which
has the IDENTITY property set. This table contains three records that are
likely to contain the automatically generated values 1, 2, and 3 in the
IDENTITY column. Provided the INDENTITY_INSERT property for this table
is enabled (by default it’s disabled, but it’s quite easy to enable), it’s quite
simple to insert another record with the value 2. The IDENTITY column will
continue to generate unique values (4, 5, 6, and so on), but it doesn’t guar-
antee the column remains unique.
Creating the Employees Table
In this section, I’ll show you how to use both Visual Web Developer and SQL
Server Management Studio, but this time we’ll create a new data table. If you’re
using Visual Web Developer, expand the database node in Database Explorer,
right-click Tables, and select Add New Table, as shown in Figure 7.8.
Figure 7.8. Adding a new table in Visual Web Developer
267
Creating the Employees Table