Introduction to Database Management Systems

advertisement
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
WHAT IS A DATABASE?
A database is used to store information about a person, place, or thing. Almost all information retrieved
from a computer is stored in a database. There are several different types of databases or what we call
database models. One of the database models used is called the relational database model. This model
stores information in files, tables, records, and fields.
STEPS WHEN CREATING A DATABASE
There are several steps that should be taken when creating a new database. These steps should usually
be in the following order, although sometimes that may not be the case.
Part 1 – Design and Document the database
The first four steps when creating a database entail documenting and designing the database. This
document will serve as a map for creating the actual database itself.
1.
2.
3.
4.
Decide what information you will store in the database and document it on paper.
Create a layout of the database and document it on paper.
Normalize the database and document it on paper.
Create a Relationship Diagram on paper.
a. Identify the Tables, Relationships, Primary Keys and Foreign Keys.
Part 2 – Create the database using Ms Office Access 2010 or any other database software.
The final steps entail the creation and setup of the database using the MS Access 2010 software.
5. Create the database structure in MS Access 2010.
6. Create the table relationships and Enforce Referential Integrity in MS Access 2010.
7. Populate the MS Access 2010 database.
a. This entails typing the information into the newly created database.
8|Page
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
STEP 1 – DECIDE WHAT INFORMATION YOU WILL STORE IN THE DATABASE.
One of the first steps in creating a database is to decide what information you will store in the database.
For example, let’s say you have started a small business using MS Word to type research papers for the
students at your school. You want to create a database to store all your charges and payments so you
can collect your fees in a timely manner. What information do you need to store and how will you make
the information for each person unique? For the purpose of this example, we will only store the
minimum amount of information needed to keep track of your charges and payments received. Figure
1.1 shows the basic information needed to create this database.
First Name
Last Name
Address
City
State
Zip Code
Home Phone
Charge Amount
Charge Date
Payment Amount
Payment Type
Payment Date
Figure 1.1
This database is a very simplistic one. Most databases you create will be much more complex. Therefore,
when you are collecting the information needed for your database, you should always consult the
people who actually do the work. You must know the business in order to create the database, so
involve the people who do the business!
9|Page
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
STEP 2 – CREATE THE LAYOUT OF YOUR DATABASE ON PAPER
Once you have decided the information to be included in your database, you must now create the
layout of the database. The layout consists of the tables, records, fields, field types, and field properties
that will be included in your database. Basically, this process of designing a solid and accurate database
is called Normalization. In order to normalize the database, you must group related fields into tables,
while eliminating any duplicate data in the database except the primary keys and foreign keys which will
relate the tables together. You also must create a primary key for most of the tables in your database.
What is a primary key? A primary key is the one field that will make each record unique in your
database. (Note: You can create a primary key from more than one field, but that is beyond the scope of
this book.) Have you ever ordered a pizza? What is the first question usually asked when you call…Could
I have your home phone number please? It’s the home phone number that makes you unique as a
Client. Your social security number makes you unique in the United States, and your Student ID makes
you unique at most Universities. We will create a unique field for each of our clients ourselves. Figure
1.2 displays the table I have created from the information I have decided I need to store in Figure 1.1. I
have created one table called Client, which will store all of the personal information needed for each
client, and all the charges and payments for each client. Each piece of this information is called a field,
and all of the fields combined for one person constitute one record. Hence, if I have 3 clients in the table
in Figure 1.2, I have 3 records and 39 fields. Notice this database has not been normalized.
Research Papers Database (Not Normalized)
Table Name:
Client
Fields:
ClientID
FirstName
LastName
Address
City
State
ZipCode
HomePhone
ChargeAmount
ChargeDate
PaymentAmount
PaymentDate
PaymentType
Field
Type
Text
Text
Text
Text
Text
Text
Text
Text
Currency
Date
Currency
Date
Text
Properties
(Field Size)
5
25
50
60
25
2
5
10
None
None
None
None
2
Primary Key
Figure 1.2
10 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
Why not just create one big table like the one above and call it a day? The problem here is that every
time a client is charged or a payment is made, all of the information needs to be re-input for each client.
This causes quite a bit of information to be duplicated and could also leave room for inaccurate
information. What if the first record has our Client listed as Rebecca Simpson, and the 2nd record for her
has her listed as Becky Simpson? Now our information is incorrect. Are Rebecca Simpson and Becky
Simpson the same people? What if we have a Rebecca Simpson at PO Box 189 and a Rebecca Simpson at
PO Box 198? Easy, you say, just look at the database to see if the information looks the same. That is
fine with a small database, but what if you have a database with thousands of records? That would be a
waste of time. Another problem that this creates is wasted disk space, because we are duplicating our
information over and over.
STEP 3 -NORMALIZE THE DATABASE
As previously stated, in order to normalize the database, you must group related fields into tables while
eliminating any duplicate data in the database except the primary keys and foreign keys which will relate
the tables together. You also must create a primary key for most of the tables in your database. Figure
1.4 shows the database normalized. (There are many different forms of Normalization. This book will
not detail the different forms.)
RESEARCH PAPERS DATABASE (NORMALIZED)
Table Name: Client
Field Type
Fields:
Client ID
First Name
Last Name
Address
City
State
Zip Code
Home Phone
Properties
Text
Text
Text
Text
Text
Text
Text
Text
Field Type
5 Characters long
25 Characters long
50 Characters long
60 Characters long
25 Characters long
2 Characters long
5 Characters long
10 Characters long
Properties
Text
Currency
Date
Field Type
5 Characters long
None
Input Mast
Properties
5 Characters long
None
2 Characters long
Input Mask
Properties
2 Characters long
20 Characters long
Table Name:
Charges
Fields:
Client ID
Charge Amount
Charge Date
Table Name:
Payments
Fields:
Client ID
Payment Amount
Payment Type
Payment Date
Table Name:
PaymentMethod
Text
Currency
Text
Date
Field Type
Fields:
MethodID
MethodType
Text
Text
Primary Key
Default Value
Input Mask
Figure 1.4
11 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
Notice now there are four tables created.
1. Client Table: Stores all the personal information about the client. Each client will only need one
record in this table, thus duplication of information and inaccuracy has been reduced drastically.
Notice the primary key is ClientID. This is the field we will use to make each record unique in the
Client table.
2. Charges Table: This table stores all information on client charges. Because we may have many
charges for one client, we will not have a primary key on this table. However, we will need a field
that tells us what charge is related to what client. For this we will use the ClientID field. Therefore,
for every Client in the Client table, we can have zero to many charges for that Client in the Charges
table.
3. Payments Table: This table stores all information on client payments. Because we may have many
payments for one client, we will not have a primary key on this table. However, we will need a field
that tells us what payment is related to what client. For this we will use the ClientID field. Therefore,
for every Client in the Client table, we can have zero to many payments for that Client in the
Payments table.
4. PaymentMethod Table: This table stores all information on payment methods. The client can pay by
Visa, Mastercard, Purchase Order (PO), Check, or Cash. We will document this on every payment.
12 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
STEP 4 - CREATE A RELATIONSHIP DIAGRAM TO IDENTIFY THE TABLES, RELATIONSHIPS,
PRIMARY KEYS, AND THE FOREIGN KEYS
The tables have been created, but how can the database know what record in the Client table relates to
records in the Charges and Payments table. In other words, how can I make sure that I can pull the
correct charges and payments information for each client? This is done by creating relationships
between the tables; hence we will create a relational database. We will depict this on paper by creating
a Relationship Diagram.
Table Name:
Foreign Key:
Client
ClientID
Foreign Key:
Primary Key:
On Payments table
ClientID
ClientID
On
table
Charges
Table Name:
Table Name:
Charges
Payments
Primary Key:
Primary Key:
None
None
Foreign Key:
PaymentType
Table Name:
On Payments table
PaymentMethod
Primary Key:
None
It is obvious that the field which makes each record in the Client table unique is the ClientID field, but
what about the Charges and Payments tables? These two tables can have many charges and payments
from one client; therefore they will not have a primary key. But, how do we relate the records in each
table. We use the ClientID field on the Charges table to relate each charge to one client on the client
table, and we use the ClientID field on the Payments table to relate each payment to one client on the
Client table. Therefore, there is a one-to-many relationship between the Client table and the Charges
table, and there is a one-to-many relationship between the Client table and the Payments table. The
ClientID field on the Charges table is called a Foreign Key, because it will relate all the records on the
Client table which uses ClientID as its Primary Key. What would be the Foreign Key on the Payments
table that will relate the Payments and Client table? It will be the ClientID on the Payments table.
13 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
COMPLETE THE FOLLOWING STEPS:
STEP 5 - CREATE THE DATABASE STRUCTURE IN MS ACCESS 2010.
1. Open Ms Office Access 2010
2. Click on the Blank Database selection
1. Click on the Blank Database Icon
If this box displays, click the OK button
If this box displays, click the OK button
14 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
3. Click on the Folder to browse.
1. Click on the Browse Folder
15 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
4. Save the file to the appropriate location on your computer. Name the file Research Papers.
1. Save the file to the correct location
2. Name the file Research Papers
3. Click the OK button
16 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
5. Click on the Create button.
1. Click on the Create button
17 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
6. Click on the arrow under the view icon and then click on Design View.
1. Click on arrow under the View Icon
2. Click on the Design View icon
7. Name the table Client, and click the OK button.
1. Type in Client
2. Click the OK Button
18 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
8. Change the first field name (ID) to Client ID.
1. Change the field name to ClientID
NOTE
As stated previously, a Primary Key is the one field that will make each record unique in the database
table. In this table, ClientID is the field that will make each client’s information unique. Notice below
that the field ClientID has a key next to it. This indicates that you have selected that field as the primary
key. When you create your first table in Access a field called ID is automatically created and a primary
key is assigned to that field. We have changed the field name to ClientID. Sometimes you will not need a
primary key on a table. You can remove the key by clicking on the field name, and then clicking on the
Key icon. You can also assign a primary key to a field by clicking on the field and then clicking on the Key
icon.
19 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
9. Change the Data Type to Text.
(Note the terms data type and field type can be used interchangeably)
1. Click the arrow
2. Click on the Text Data Type
20 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
10. Change the Field Size to 5.
(You must have the ClientID field selected to show the properties for the ClientID field.
(Note: This will limit the maximum number of characters in the field to 5)
(Note: Field size is one type of property. Notice all the other properties that can be set)
Make sure the ClientID field is selected
21 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
11. Create the remainder of the Client table as shown on Figure 1.5 and then close the Client table.
Table Name: Client
Field Type Properties (Field Size)
Fields:
ClientID
Text
5
Primary Key
FirstName
Text
25
LastName
Text
50
Address
Text
60
City
Text
25
State
Text
2
ZipCode
Text
5
HomePhone
Text
10
Figure 1.5
2. Close the table
1. Create the fields
Figure 1.2
3. Click the Yes button to save the table.
22 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
12. Click on the State field in the upper pane to select the field. Change the default value in the field
properties to OH.
1. Click on the State Field to select it.
2. Change the default value in the Field
Properties to, OH
We have added a default value of OH to the state field properties. This will cause the state field to
initially store the value OH in every record. However; this value is not set in stone. You can change the
value in the field at any time. The default value property is good to use if a certain field will contain the
same information in it most of the time. For example, we do most of our business in Ohio, therefore; we
have set the default value to OH.
23 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
13. Click on the HomePhone field in the upper pane to select the field. Click on the Input Mask
selection in the Field Properties, and then click on the ellipsis ( … ) next to the Input Mask
selection.
1. Click on the HomePhone field to select it
2. Click on the Input Mask Selection
3. Click on the ellipsis ( … )
4. Click on the Yes Button
24 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
14. Click on the Phone Number selection, and then click on Finish.
1. Select the Phone Number Input Mask
2. Click on the Finish Button
We have added an input mask of (999) 999-9999 to the HomePhone field property. This will save us the
time and hassle of having to add the parentheses and hyphen to the home phone field when we type it
in. Basically, the field is preformatted for us. All we have to do is input the actual phone number.
25 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
15. Close the Client table.
1. Close the Client Table
2. Click on the Yes Button
26 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
1. Click on the Create tab, and then click on the Table Design icon to create the Charges table.
1. Click on the Create tab
2. Click on the
Table Design
icon
27 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
2. Create the structure for the Charges table using the following information.
Table Name:
Charges
Field Type
Field Size (Properties)
Fields:
ClientID
Amount
ChargeDate
Text
Currency
Date
5
None
None
1. Create the fields for the
Charges table
MAKE SURE YOUR TABLE LOOKS EXACTLY LIKE THIS ONE.
28 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
3. Click on the ChargeDate field in the upper pane to select the field. Click on the Input Mask
selection in the Field Properties, and then click on the ellipsis ( … ) next to the Input Mask
selection. Click the yes button, when asked to Save now.
1. Click on the ChargeDate field
4. Save the changes
2. Click in the Input Mask Text Box
3. Click on the ellipsis (…)
4. Name the table, Charges and click the OK button. Click the No button when asked, Do you want
to create a primary key now? Click on the short date input mask option, and click on finish.
1. Type in Charges as the table name
2. Press the Ok button
29 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
3. Click the No button
4. Click the Short Date selection
5. Click the Finish button
30 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
5. Close the table and save the changes.
1. Close the
table
2. Click the Yes button
31 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
6. Follow the same steps to create the Payments table and the PaymentMethod table. Be
sure to create an input mask of short date for the PaymentDate field.
Table Name:
Payments
Field Type
Field Size (Properties)
Fields:
ClientID
Amount
PaymentDate
PaymentType
PaymentMethod
5
None
None
2
Field Size (Properties)
No Primary Key
Table Name:
Text
Currency
Date
Text
Field Type
Fields:
MethodID
MethodType
Text
Text
2
20
Primary Key
You should now have 4 Tables.
1. Client—Primary Key ClientID
2. Charges—No Primary Key
3. PaymentMethod—Primary Key MethodID
4. Payments—No Primary Key
(Note: These tables do not have to be in this order)
32 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
STEP 4 - ENFORCE REFERENTIAL DATA INTEGRITY
Now that the relationships between the tables have been established, we need to closely examine the
relationships between each of these tables. First, let’s take a look at the relationship between the Client
table and the Charges table. Each record in the Client table has a ClientID field that makes each record
unique. Thus we know that J7500 is the record for Nancy Davolio only. What if we had a record in the
Charges table with a ClientID of J9900 but, there was no J9900 record in the Client table. How would we
know what Client to charge, or where to send the bill? We won’t, and therefore records in the Charges
table should always have a matching record in the Client table. The Client table is known as the parent in
this relationship, and the Charges table is known as the child. When designing databases we never want
to have orphans in our tables. We can eliminate orphans by enforcing referential data integrity.
Therefore, if you try to add record J9900 to the Charges table, which is the child table in this
relationship, and there is no record J9900 in the Client table, which is the parent table in the
relationship, you will receive an error message.
In our relationship diagram we have two relationships.
The Client table is related to the Charges table.
 Client Table is the parent in this relationship.
 Charges Table is the child in this relationship.
 There is a one-to-many relationship between the Client Table and the Charges table
o For every one record on the Client table there can be zero to many related records
on the Charges table
The Client table is related to the Payments table.
 Client Table is the parent in this relationship.
 Payments Table is the child in this relationship.
o For every one record on the Client table there can be zero to many related records
on the Payments table
The PaymentMethod table is related to the Payments table.
 PaymentMethod Table is the parent in this relationship.
 Payments Table is the child in this relationship.
o For every one record on the PaymentMethod table there can be zero to many
related records on the Payments table
33 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
STEP 6 - CREATE THE TABLE RELATIONSHIPS, AND ENFORCE REFERENTIAL INTEGRITY
USING MS ACCESS 2010.
1. Click on the Database Tools tab, and then click on the Relationships Icon.
2. Click on the Database Tools tab
3. Click on the Relationships icon
MAKE SURE ALL TABLES ARE CLOSED
34 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
2. Click on the Charges selection and click on the add button, then add the remainder of the
tables as shown, and finally click on the Close button.
1. Click on the Show Table icon
2. Click on the Charges table
3. Click the Add button
35 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
3. Arrange the tables on the screen as shown.
MAKE SURE YOUR TABLES LOOK EXACTLY LIKE THE ONES SHOWN.
36 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
4. Click on the left mouse button on the ClientID field in the Client table. While holding down
the left mouse button drag the field over to the ClientID in the Charges table. You will have a
relationship dialog box pop up as shown below.
2. While holding the left mouse button down, drag the ClIientID field
from the Client table over to the ClientID field on the Charges table
Charges table
1. Left click on the
ClientID field in the
Client table
37 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
5. Click on the Enforce Referential Integrity, Cascade Update Related fields, and Cascade
Delete Related Records check boxes and then click the Create button.
**NOTE** We will discuss later the importance of the Cascade Update Related Fields
and Cascade Delete Related Fields Check box.
4. Click the Create
button
1. Click on the Enforce Referential Integrity checkbox
2. Click on the Cascade Update Related fields checkbox
3. Click on the Cascade Delete Related Records checkbox
38 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
6. Click the left mouse button on the ClientID field in the Client table and drag it over the
ClientID in the Payments table. You will have a relationship dialog box pop up as shown
below. Click on the Enforce Referential Integrity, Cascade Update Related fields, and
Cascade Delete Related Records check boxes and then click the Create button.
**NOTE** We will discuss later the importance of the Cascade Update Related Fields
and Cascade Delete Related Fields Check box.
3. While holding the left mouse button down, drag the ClIientID field
from the Client table over to the ClientID field on the Payments table
Charges table
1. Left click on the
ClientID field in the
Client table
6. Click the Create
button
3. Click on the Enforce Referential Integrity checkbox
4. Click on the Cascade Update Related fields checkbox
5. Click on the Cascade Delete Related Records checkbox
39 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
7. Click the left mouse button on the MethodID field in the PaymentMethod table and drag it
over to the PaymentType field in the Payments table. You will have a relationship dialog box
pop up as shown below. Click on the Enforce Referential Integrity, Cascade Update Related
fields, and Cascade Delete Related Records check boxes and then click the Create button.
2. While holding the left mouse button down, drag the MethodID field from
the PaymentMethod table over to the PaymentType field on the
Payments table
6. Click the Create
button
3. Click on the Enforce Referential Integrity checkbox
4. Click on the Cascade Update Related fields checkbox
5. Click on the Cascade Delete Related Records checkbox
1. Left click on the
MethodID field in the
PaymentMethod table
40 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
8. Close and save the relationships.
1. Click the Close icon
2. Click the Yes button
41 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
STEP 7 – POPULATE THE DATABASE.
Now that you have created the structure of the database, it is time to input your client information.
12. Double click on the Client Table to open it up in Datasheet View and type in the information for
the following records.
1. Double click on the
Client Table
NOTE
 * indicates a blank record where you can input information.
o This row will always show up. It is not considered a record. It is just a
holding place to add new records.
 OH is the default for the state field.
o It will always show up at first, but you can change the OH to any other
state you wish.
 When you type in the information, don’t worry if it doesn’t display
completely in the cell. It is there, you just can’t see it.
42 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
2. Type in the information in shown in figure 1.6.
Client Table
ClientID
FirstName
LastName
Address
City
State Zipcode
HomePhone
J7500
Nancy
Davolio
507 - 20th Ave. E. Apt. 2A
Seattle
WA
(614)-29298122 3900
J7505
John
Smith
123 Main Street
Columbus
OH
(740)-36543081 9192
J7510
Mark
Johnson
420 Broad Street
Columbus
OH
(740)-36542001 7700
J7515
Jen
Griffin
500 High Street
Columbus
OH
(614)-29243081 4566
J7520
Jennifer
King
400 Walnut Street
Cincinnati
OH
(614)-88841098 9930
J7525
Karen
Day
250 Fifth Street
Cincinnati
OH
(614)-29341077 5001
J7530
Jeff
Bair
125 Plum Street
Cincinnati
OH
(740)-36541077 4478
J7535
Nancy
Beard
10 South Wacker
Chicago
IL
(740)-36560639 4879
J7540
Brad
Wallace
120 South LaSalle
Chicago
IL
(740)-36560639 4421
J7545
Joe
Davis
15 West Washington
Chicago
IL
(614)-44360221 0988
J7550
Tim
Smith
908 W. Capital Way
Tacoma
WA
(614)-29398401 9655
J7555
Brandon
Coake
722 Moss Bay Blvd.
Kirkland
WA
(614)-55598033 9333
J7560
Margaret
Peacock
4110 Old Redmond Rd.
Redmond
WA
(614)-29398052 8857
J7565
Matthew
Dunn
14 Garrett Hill
Seattle
WA
(740)-36598105 4433
J7570
George
Nagy
722 DaVinci Blvd.
Kirkland
WA
(740)-36598034 2241
J7575
Deborah
Peterson
305 - 14th Ave. S. Suite 3B
Seattle
WA
(740)-36598128 9031
Figure 1.6
43 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
1. Input the information in the PaymentMethod table as shown in figure 1.6. DO THIS BEFORE ADDING
INFORMATION TO THE Charges and Payments Table.
2. Input the information in the Charges table, and the Payments table as shown in figure 1.6.
3. After you have finished inputting all of the information, completely close the Research Papers
database.
Charges Table
ClientID
Amount
PaymentMethod Table
ChargeDate
MethodID MethodType
J7500
$100.00
5 /5 /2008
J7500
$150.00
3 /22/2008
J7505
$150.00
3 /22/2008
J7510
$300.00
8 /8 /2008
J7515
$50.00
4 /15/2008
J7520
$50.00
4 /21/2008
J7520
$50.00
3 /27/2008
J7520
$100.00
7 /6 /2008
J7525
$100.00
9 /13/2008
J7530
$200.00
10/13/2008
J7535
$100.00
12/1 /2008
J7540
$100.00
11/28/2008
J7540
$100.00
5 /12/2008
J7500
1
$100.00
1 /16/2008
J7545
$100.00
6 /17/2008
J7500
3
$200.00
3 /3 /2008
J7550
$200.00
7 /24/2008
J7500
5
$50.00
2 /12/2008
J7555
$50.00
8 /19/2008
J7505
2
$250.00
1 /16/2008
J7560
$50.00
4 /24/2008
J7510
2
$250.00
2 /22/2008
J7565
$50.00
4 /15/2008
J7510
2
$100.00
2 /28/2008
J7565
$100.00
4 /22/2008
J7510
1
$100.00
1 /2 /2008
J7565
$100.00
5 /24/2008
J7515
1
$75.00
1 /21/2008
J7565
$100.00
5 /22/2008
J7530
4
$50.00
3 /8 /2008
J7570
$50.00
4 /21/2008
J7535
5
$200.00
3 /8 /2008
J7575
$50.00
3 /27/2008
J7545
5
$125.00
2 /16/2008
1
Visa
2
Mastercard
3
PO
4
Check
5
Cash
Type in the information for the
PaymentMethod table First
Payments Table
ClientID
PaymentType Amount PaymentDate
Figure 1.6
44 | P a g e
Copyright © 2013 Lori A. Rice
5th Edition
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
CASCADE UPDATE RELATED RECORDS/CASCADE DELETE RELATED RECORDS
If you recall, when we enforced referential data integrity in MS Access 2007, we checked two boxes to
Cascade Update Related Records and Cascade Delete Related Records. These options ensure that our
database has no orphans. If you remember correctly, when we enforce referential data integrity the
database will not allow any orphans to be input in the tables. But, orphans can still exist in your
database even if you click the enforce referential data integrity checkbox. For example, if you look in the
database above you will notice Nancy Davolio, ClientID J7500, has 2 records in the Charges table, and 3
records in the Payments table. What would happen if I deleted the record for Nancy Davolio in the Client
table? Now there are 2 orphans in the Charges table, and 2 orphans in the Payments table. Likewise, if I
change the ClientID for Nancy Davolio to J7900, I also produce orphans in both the Charges table and
the Payments table. However, if I click the checkboxes to Cascade Update Related Records, and Cascade
Delete Related Records, if I delete the parent, Nancy Davolio, ClientID J7500, I will delete all the J7500
children in all of the related tables. But, if I delete the children, J7500, in the Charges or Payments table,
I will not delete the parent J7500 in the Client table. The Update Related Records checkbox works the
same way as the Cascade Delete Related Records, only it updates the children ClientID when the parent
ClientID is updated. Remember, it only goes one way. If I delete the parent, I delete the children, but if I
delete the children, I do not delete the parent. If I update the ClientID for the parent, the ClientID for all
the related children will be updated, but if I update the clientID for the children table, the ClientID for
the parent table will not be updated.
Page 45
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
Possible Scenarios when the following boxes are checked when creating relationships:
Enforce Referential Integrity, Cascade Update Related Fields, Cascade Delete Related Records
NOTE:
DO NOT MAKE THESE CHANGES IN THE DATABASE
THESE ARE EXAMPLES ONLY
Action
Delete record J7500 in the Client table
Associated Action
All records in the Charges table with ClientID
J7500 will be deleted.
All records in the Payments table with ClientID
J7500 will be deleted.
Delete any J7500 record in the Charges Table
Only that one J7500 record will be deleted in
the Charges Table
Delete any J7500 record in the Payments Table
Only that one J7500 record will be deleted in
the Payments Table
Change ClientID J7500 to J9900 in the Client table
All records in the Charges table with
ClientID J7500 will be changed to ClientID J9900
All records in the Payments table with
ClientID J7500 will be changed to ClientID J9900
Delete record with MethodID of 1 in the
PaymentMethod table.
All records in the Payments table with
PaymentType of 1 will be deleted.
Change record with MethodID 1 to MethodID 6 in the
PaymentMethod table.
All records in the Payments table with
PaymentType of 1 will be changed to
PaymentType of 6.
Change record J7500 from PaymentType of 1 to
PaymentType of 6 in the Payments table.
If a record with MethodID 6 exists in the
PaymentMethod table the record in the
Payments table with will change accordingly.
If a record with MethodID 6 does not exist in
the PaymentMethod table, you will receive the
message, “Referential Data Integrity has been
Violated”, and you will not be able to make the
change to the record.
Page 46
Download