Databases Reference
In-Depth Information
Primary and Candidate Keys
Primary Keys Figure 5.2 contains two relations, the SALESPERSON relation
and the CUSTOMER relation, from General Hardware Company's relational
database. The SALESPERSON relation has four rows, each representing one
salesperson. Also, the SALESPERSON relation has four columns, each representing
a characteristic of salespersons. Similarly, the CUSTOMER relation has nine rows,
each representing a customer, and four columns.
A relation always has a unique primary key . A primary key (sometimes
shortened in practice to just ''the key'') is an attribute or group of attributes whose
values are unique throughout all rows of the relation. In fact, the primary key
represents the characteristic of a collection of entities that uniquely identifies each
one. For example, in the situation described by the relations in Figure 5.2, each
salesperson has been assigned a unique salesperson number and each customer
has been assigned a unique customer number. Therefore the Salesperson Number
attribute is the primary key of the SALESPERSON relation and the Customer
Number attribute is the primary key of the CUSTOMER relation. As in Figure 5.2,
we will start marking the primary key attribute(s) with a single, solid underline.
The number of attributes involved in the primary key is always the minimum
number of attributes that provide the uniqueness quality. For example, in the
SALESPERSON relation, it would make no sense to have the combination of
Salesperson Number and Salesperson Name as the primary key because Salesperson
Number is unique by itself. However, consider the situation of a SALESPERSON
(a) SALESPERSON relation
Salesperson
Salesperson
Commission
Year
Number
Name
Percentage
of Hire
137
Baker
10
1995
186
Adams
15
2001
204
Dickens
10
1998
361
Carlyle
20
2001
(b) CUSTOMER relation
Customer
Customer
Salesperson
Number
Name
Number
HQ City
0121
Main St. Hardware
137
New York
0839
Jane's Stores
186
Chicago
0933
ABC Home Stores
137
Los Angeles
1047
Acme Hardware Store
137
Los Angeles
1525
Fred's Tool Stores
361
Atlanta
1700
XYZ Stores
361
Washington
1826
City Hardware
137
New York
FIGURE5.2
General Hardware Company
relational database
2198
Western Hardware
204
New York
2267
Central Stores
186
New York
 
Search WWH ::




Custom Search