Database Reference
In-Depth Information
Salary
Currency value from 000000.00 to 999999.99
HireDate
Legal values for date greater than January 1, 1900
Identifiers for Instances
Go back to Figure 6-5 displaying sample attributes for object STUDENT. You have
noted that the set of values in each row describes a single instance. But do you know
which set describes a particular instance? If asked “what is the address of Rob
Smith?”, how can you find the address from the database? You can go through all
instances of the object STUDENT and check for the name value Rob Smith and
then find the value for the address. What if there are three students in the univer-
sity with the same name Rob Smith? Which Rob Smith are we referring to?
You need a method to identify a particular instance of an object. Obviously,
values of an attribute may be used to identify particular instances. You tried to do
that by looking for STUDENT instances with value “Rob Smith” for the attribute
StudentName. However, you could not say for sure that you found the correct
student because of the possibility of duplicate values for this attribute. On the other
hand, if you had used values of the attribute StudentID, you could uniquely iden-
tify the student. What is the address of the student with StudentID 123456? It is
Mary Williams; nobody else has that StudentID. Therefore, values of the attribute
StudentID can be used to uniquely identify instances of STUDENT.
Attributes whose values can be used to uniquely identify instances of an object
are known as identifiers. They are also known as keys for the object. Now, review
the attributes for the object STUDENT. StudentName, StudentPhone, or Student-
Major cannot be used to identify instances uniquely. This is because these may have
duplicate values in the set of instances for the object. Therefore, any attribute that
is likely to have duplicate values does not qualify to be a key or identifier for an
object.
How about the attributes StudentID and SocSecNo? Either of these attributes
qualifies to be a key for STUDENT. Such attributes are called candidate keys .One
of the candidate keys is chosen to be the identifier for the object. The primary key
of an object is a candidate key selected as the identifier for the object. For some
objects, one attribute alone will not be enough to form the identifier. You may have
to use a combination of two or more attributes as the identifier. In such cases, the
primary key is a composite key .
Refer back to our discussion of null values for attributes. Can an attribute
with null values qualify to be a key? If null values are permitted for an attribute,
then many instances of the object may have null values for this attribute. That
means this attribute is useless for identifying those instances for which the attribute
has null values. Attributes for which null values are allowed cannot be used as
keys.
Here are a few tips on selecting a primary key:
Obviously, exclude attributes for which null values are allowed.
If possible, prefer a single attribute to a combination of multiple attributes.
Select an attribute whose values will not change for the life of the database
system.
Search WWH ::




Custom Search