In Chapter 5, you??™ll see an example of amultivalued
primary key. For now, it??™s enough to know that they exist.
?– Note Applying a PRIMARY KEY constraint on a field also generates a unique index created on it by
default. Indexes are objects that improve performance of many database operations, dramatically speeding
up your web application (you??™ll learn more about this later in the ???Indexes??? section of this chapter).
CHAPTER 4 ?– CREATING THE PRODUCT CATALOG: PART 1 72
Unique Columns
UNIQUE is yet another kind of constraint that can be applied to table columns. This constraint is
similar to the PRIMARY KEY constraint in that it doesn??™t allow duplicate data in a column. Still,
there are differences. Although there is only one PRIMARY KEY constraint per table, you are
allowed to have as many UNIQUE constraints as you like.
Columns that have the UNIQUE constraint are useful when you already have a primary key
but still have columns (or groups of columns) for which you want to have unique values. You
can set name to be unique in the department table if you want to forbid repeating values.
The facts that you need to remember about UNIQUE constraints follow:
??? The UNIQUE constraint forbids having identical values on the field.
??? You can have more than one UNIQUE field in a data table.
??? A UNIQUE field is allowed to accept NULL values, in which case it will accept any number
of them.
Pages:
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146