My Part
My Part
Here are some questions to think about: How did cutting-edge data analy-
sis technology improve decision making by Envision’s drivers in races? How can
Envision maintain its advantages from data analysis in the future?
Bit 0
Key Field
(Primary Key)
Figure 6.2
A Relational Database Table
A relational database organizes data in the form of two-dimensional tables. Illustrated here is a table for the entity SUPPLIER, showing how it
represents the entity and its attributes. Supplier_Number is the key field.
We could use the supplier’s name as a key field. However, if two suppliers had the
same name (which does happen from time to time), supplier name would not uniquely
identify each, so it is necessary to assign a special identifier field for this purpose. For
example, if you had two suppliers, both named “CBM,” but one was based in Dayton
and the other in St. Louis, it would be easy to confuse them. However, if each has a
unique supplier number, such confusion is prevented.
We also see that the address information has been separated into four fields:
Supplier_Street, Supplier_City, Supplier_State, and Supplier_Zip. Data are sepa-
rated into the smallest elements that one would want to access separately to make
it easy to select only the rows in the table that match the contents of one field, such
as all the suppliers in Ohio (OH). The rows of data can also be sorted by the con-
tents of the Supplier_State field to get a list of suppliers by state regardless of their
cities.
So far, the SUPPLIER table does not have any information about the parts that a par-
ticular supplier provides for your company. PART is an entity separate from SUPPLIER,
and fields with information about parts should be stored in a separate PART table.
Why not keep information on parts in the same table as information on suppli-
ers? If we did that, each row of the table would contain the attributes of both PART
and SUPPLIER. Because one supplier could supply more than one part, the table
would need many extra rows for a single supplier to show all the parts that the sup-
plier provided. We would be maintaining a great deal of redundant data about sup-
pliers, and it would be difficult to search for the information on any individual part
because we would not know whether this part is the first or the 50th part in this
supplier’s record. Examine Figure 6.3, which illustrates a separate table, PART,
that should be created to store data about parts (in this case, part number, part
name, and unit price) and solve this problem.
The PART table would also have to contain another field, Supplier_Number, so
that you would know the supplier for each part. It would not be necessary to keep
repeating all the information about a supplier in each PART record because having a
Supplier_ Number field in the PART table allows you to look up the data in the fields
of the SUPPLIER table.
Notice that Supplier_Number appears in both the SUPPLIER and the PART ta-
bles. In the SUPPLIER table, Supplier_Number is the primary key. When the field
Supplier_Number appears in the PART table, however, it is called a foreign key and is
essentially a look-up field to find data about the supplier of a specific part. Note that
the PART table would itself have its own primary key field, Part_Number, to identify
each part uniquely. This key is not used to link PART with SUPPLIER but could be
used to link PART with a different entity.
As we organize data into tables, it is important to make sure that all the attributes
for a particular entity apply only to that entity. If you were to keep the supplier’s ad-
dress with the PART record, that information would not really relate only to PART: It
would relate to both PART and SUPPLIER. If the supplier’s address were to change, it
would be necessary to alter the data in every PART record rather than only once, in the
SUPPLIER record.
ESTABLISHING RELATIONSHIPS
Now that we’ve broken down our data into a SUPPLIER table and a PART table,
we must make sure we understand the relationship between them. A schematic
called an entity-relationship diagram clarifies table relationships in a relational data
base. The most important piece of information that an entity-relationship dia-
gram provides is the manner in which two tables are related to each other. Tables
in a relational database may have one-to-one, one-to-many, and many-to-many
relationships.
An example of a one-to-one relationship is a human resources system that stores
confidential data about employees. The system stores data, such as the employee
name, date of birth, address, and job position, in one table and confidential data
about that employee, such as salary or pension benefits, in another table. These two
tables pertaining to a single employee would have a one-to-one relationship because
each record in the EMPLOYEE table with basic employee data has only one related
record in the table storing confidential data.
The relationship between the SUPPLIER and the PART entities in our database
is a one-to-many relationship. Each supplier can supply more than one part, but each
part has only one supplier. For every record in the SUPPLIER table, many related
records might be in the PART table.
Examine Figure 6.4, which illustrates how an entity-relationship diagram would
depict this one-to-many relationship. The boxes represent entities. The lines connect-
ing the boxes represent relationships. A line connecting two entities that ends in two
short marks designates a one-to-one relationship. A line connecting two entities that
ends with a crow’s foot symbol preceded by a short mark indicates a one-to-many rela-
tionship. The text above the line is read left to right (i.e., SUPPLIER provides PART),
while the text below the line is read right to left (i.e., PART is supplied by SUPPLIER).
Figure 6.4 shows that each part has only one supplier, but the same supplier can pro-
vide many parts.
We would also see a one-to-many relationship if we wanted to add to our database
a table about orders because one supplier services many orders. The ORDER table
would contain only the Order_Number and Order_Date fields. Examine Figure 6.5,
which illustrates a sample order report showing an order of parts from a supplier. If
you look at the report, you can see that the information on the top-right portion of
the report (the Order number and the Order date) comes from the ORDER table. The
actual line items ordered are listed in the lower portion of the report.
Because one order can be for many parts from a supplier and because a single part
can be ordered many times on different orders, this creates a many-to-many relationship
between the PART and ORDER tables. Whenever a many-to-many relationship exists
provides
SUPPLIER PART
is supplied by
Figure 6.4
A Simple Entity-Relationship Diagram
This diagram shows the relationship between the entities SUPPLIER and PART.
between two tables, it is necessary to link these two tables in a table that joins this infor-
mation. Creating a separate table for a line item in the order would serve this purpose.
This table is often called a join table or an intersection relation. This join table contains
only three fields: Order_Number and Part_Number, which are used only to link the
ORDER and PART tables, and Part_Quantity. If you look at the bottom-left part of the
report, this is the information coming from the LINE_ITEM table.
We would thus wind up with a total of four tables in our database. Examine
Figure 6.6, which illustrates the final set of tables. Note that the ORDER table
does not contain data on extended price because that value can be calculated by
PART LINE_ITEM
3503 1/16/2023
3504 1/17/2023
SUPPLIER
Figure 6.6
The Final Database Design with Sample Records
The final design of the database for suppliers, parts, and orders has four tables. The LINE_ITEM table is a “ join table” that eliminates the
many-to-many relationship between ORDER and PART.
Figure 6.7
Entity-Relationship Diagram for the Database with Four Tables
This diagram shows the relationships among the SUPPLIER, PART, LINE_ITEM, and ORDER entities.
Figure 6.8
Name Human Resources
SSN Benefits
Health_Care View Database with Multiple
Views
A single human resources
database provides many
Employee_ID
views of data, depending
Name
SSN on the information
Database
Position requirements of the user.
Management
Date_Hired System Illustrated here are two
Gross_Pay possible views, one of
Net_Pay interest to a benefits
Life_Insurance specialist and one of
Pension_Benefit
Health_Care
interest to a member of
Name
the company’s payroll
SSN Payroll
Gross_Pay department.
View
Human Resources Net_Pay
Database