Professional Documents
Culture Documents
To complete this lab, follow the steps outlined in the “Logging into Lynda.com” page in myClasses. Please watch the Access 2013
Essential Training with Adam Wilbert and then, practice your Access skills to create a simple database. Follow the steps below to
complete.
SET UP: As a starting point, you should have an Access database file containing four tables (Customers, Products, Sales, and Sales
Detail) as defined in Part 1
PART1: CREATING PRIMARY KEYS: In each table, we need to set up a primary key(s) that will uniquely identify and index the data
records contained in that table.
1. Open the Customers table, click on the VIEW button (top left) to show the design view.
2. Click on the gray box (row header) next to CustomerID to select the row, click on the Primary Key
button. This will add a little key next to the
CustomerID to show that the values in this column
MUST BE unique.
3. NOTE: Because primary keys MUST be unique, if at
any point, if you get an error message that says
you can't create a row of information because of a
duplicate value, check your tables. Make sure all
the data is unique.
4. Open the Products table, set the ProductID field as your primary key. (photo below)
5. Likewise, set the Order ID as the primary key in the Sales table.(photo below)
6. The Sales Detail table is a bit trickier, because it has two (2) primary keys. Intuitively, this is because the combination of
SalesID and ProductID make a single unique identifier for that table (i.e. a given product can show up no more than once in
a given order). To declare two primary keys, highlight both fields and click on the Primary Key button.
1
INFO 211 PSB
PART 2: DEFINING RELATIONSHIPS: Now that we have setup our primary keys, we are ready to define the relationships between the
four tables. This allows us to find related data easily. For example, we might want to find out how many times a customer has
ordered product ZZ-B01. Relationships are what allows that to happen.
7. Close all open tables - you can only create relationships when all tables are closed.
8. Click on the Database Tools ribbon toward the top of your screen. Next, click on the Relationships button.
9. This will launch the Show Table box. Double click on each table name to add
them to the screen.
10. Once you see all tables (you might have to move the Show Table screen around
to see them) close the Show Table screen.
11. All four tables should appear as displayed below.
2
INFO 211 PSB
12. The ordering of the tables is not very convenient, as the related fields with matching relationships do not line up. Move the
tables around to match the screenshot below.
13. We know that the CustomerID field in the Customers table is the same thing as the CustomerID field in the Sales table. We
need to tell Access that the data in each table should match and that the data in these two tables are directly related to one
another, so we need to create a relationship between them. To do this, move your mouse pointer over CustomerID in the
Customers table and click and hold your mouse button. Next, drag the mouse (while still holding down the mouse button)
over to the Customer ID field in the Sales table. Release the mouse button. This will launch the Edit Relationships box.
14. Double check that the tables shown at the top are correct.
15. Click on the “Enforce Referential Integrity” checkbox. Notice the
type of relationship Access is trying to create: One-To-Many. This
means that for every one customer, there will be many sales.
16. Now, click Create.
*NOTE: If you get an error message that says you can't create the
relationship because the table is in use, it is because your table is open.
Close all tables except the relationship window and try again.
3
INFO 211 PSB
17. Now a black line appears linking the Customer ID fields in both tables. The One-To-Many relationship is represented with a
1, on the one side, and an infinity sign on the many side.
18. Repeat this process and create a relationship connecting OrderID fields in the Sales and Sales Detail tables. Always drag
from the ONE side of the relationship. In this case drag from Sales table and drop on Sales Detail table.
19. Finally, create a relationship between the ProductID fields in the Sales Detail and Products tables. Your relationship screen
should now look as follows:
20. When you are finished, close the relationships window and save changes as prompted.
PART 3: CREATING FORMS: Now that we have database tables with correct primary keys and properly defined relationships, we can
now easily create data-entry forms that will enable us to easily add new records to our linked database tables.
21. Click once on the Sales table on the left hand side of the screen, and then click on the Create ribbon at the top of the
screen. Now, click on the Form button.
4
INFO 211 PSB
22. This will automatically create a data entry form in which you can enter data that will be stored in the Sales table. Notice
that Access also automatically includes the linked records from the Sales Detail table.
*NOTE: as seen in the picture, there are two sets of controls - the bottom set scrolls through the orders and the top set through the
details of that order. In this example, Order # 1, was made by customer G1 (Giant), in July. On that order, Giant purchased 23 boxes
of ZZ-B01 and 331 boxes of ZZ-B04.
23. This data is being pulled from the Excel tables we imported but the purpose of a
form is to provide a place for entry. You can use this to add your own information
as well and it will then be automatically be stored in the appropriate tables. Scroll
through your Sales Orders until you get to OrderID 10. You will notice that this
was an order place on 1/15/2017 by the Wawa in Dover. You can see that on this
particular day and order, they purchased 295 boxes of ZZ-B01 and 24 boxes of
ZZ-B04. Let’s assume you are a data entry intern and Wawa also purchased 20
boxes of ZZ-B06 on this same order. You can add this by entering the data just
below the ZZ-B04 entry. Add the productID and the quantity.
24. Close the form and save as Sales Form if you have not yet saved it.
25. Since this new entry is stored now in the designated tables, if we open the Sales Detail table and scroll down to orderID 10,
we will see an entry containing this order: OrderID 10, ZZ-B06, 20 boxes. Close and save the table if prompted
5
INFO 211 PSB
26. We can also use the entry form to add a new order entry. Let's assume this time, that you are working for a distribution
company and your job is to take orders as they come in on the phone. Open the Sales Form you just created, using the
bottom controls, scroll to the end of the orders (order #27), if you scroll to a new order (#28) you can add all the details for
this new order. Notice, the OrderID is automatically generated so you just have to input CustomerID, Date, ProductID, and
Quantity as shown here:
27. Close and save your form if prompted.
28. Let's go check to make sure everything was entered correctly. Open your Sales table. Scroll down to your newly created
sales order (#28) and click the + next to the order. You should see each of the three products purchased on that order. Also
notice the Sales Detail table has the correct information as well.
29. Now that you have edited order 10 and entered order 28. Practice by entering a few more orders (# 29 & 30), each with a
few products in each order.
Congratulations!
You are finished Part 1 and Part 2. Make sure you read the grading Rubric below.
6
INFO 211 PSB
Added Orders #28, 29, & 30 with a couple of products each 6