Top Banner
AOIT Database Design Lesson 9 Creating a Relational Database Student Resources Resource Description Student Resource 9.1 Scenario: Naming Conventions Student Resource 9.2 Checklist: Relational Database Student Resource 9.3 Reference: Naming Conventions Student Resource 9.4 Note Taking: Data Integrity Student Resource 9.5 Reading: Data Integrity Student Resource 9.6 Defining Format: Data Integrity Student Resource 9.7 Tutorial: Using the Relationship Tool to Specify Foreign Keys in Access Student Resource Procedural Steps: Setting Up Keys and Relationships Copyright © 2009–2014 NAF. All rights reserved.
50

Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

Aug 13, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database Design

Lesson 9Creating a Relational Database

Student Resources

Resource Description

Student Resource 9.1 Scenario: Naming Conventions

Student Resource 9.2 Checklist: Relational Database

Student Resource 9.3 Reference: Naming Conventions

Student Resource 9.4 Note Taking: Data Integrity

Student Resource 9.5 Reading: Data Integrity

Student Resource 9.6 Defining Format: Data Integrity

Student Resource 9.7 Tutorial: Using the Relationship Tool to Specify Foreign Keys in Access

Student Resource 9.8 Procedural Steps: Setting Up Keys and Relationships in Access

Student Resource 9.9 Worksheet: Validation Rules

Student Resource 9.10 Reference: Syntax for Common Validation Rules

Student Resource 9.11 Culminating Project Work: Setting Field Properties and Enforcing Business Rules

Student Resource 9.12 Tutorial: Importing Data Using the Import Wizard

Copyright © 2009–2014 NAF. All rights reserved.

Page 2: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Student Resource 9.1

Scenario: Naming ConventionsStudent Names:______________________________________________________ Date:___________

Directions: In this scenario, a group of students have created a database to store information about their favorite songs. Your role is to help them enforce the naming conventions they have established. Follow the instructions below to provide your input.

A group of students is creating a database to store information about the students’ favorite songs. The database has three tables:

Album

Artist

Track

To make their database easy for everyone to understand and use, the students have established the following standard naming conventions, and they want to make sure all attributes (columns) adhere to these conventions.

All names are descriptive, readable, and concise.

All names are in mixed case (the first letter of each word is in uppercase).

All table names are singular (Shipper, not Shippers).

Abbreviations are used to shorten names to fewer than 30 characters when necessary.

All names are alphanumeric (they use alphabetic and numeric characters and no special characters except the underscore).

The words in each name are separated by an underscore (Last_Name).

Before they start putting data in their database, the students would like you to check and make sure all the attribute (column) names in the table on the following page adhere to their naming conventions. If they do not adhere, please suggest an acceptable name. Be sure your “acceptable” example does not violate any of the other rules or guidelines in the list!

The first one is done for you as an example.

Copyright © 2009–2014 NAF. All rights reserved.

Page 3: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Attributes (Column) Acceptable? (Y/N)

If Not Acceptable, Suggested Improvement

Table: Album

LABEL N Label

album_price

Categories

Sales_ _For_Year_2009

Table: Artist

Country_of_Origin

Artist Name

ArtistID

Birthdate

Table: Track

minutes:seconds

TRACK#

Copyright © 2009–2014 NAF. All rights reserved.

Page 4: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Student Resource 9.2

Checklist: Relational Database Directions: Use this checklist to make sure you have successfully completed all the steps before you submit your relational database for assessment. Check off each item when you complete it. Use the rubric that your teacher gives you to ensure that each piece meets or exceeds the assessment criteria.

You have placed in your project portfolio a document that lists all of the naming conventions that your culminating project adheres to.

All of the tables with all of their columns are entered in your culminating project database. All names adhere to your naming conventions.

All primary keys are entered correctly for each table in your database. The field properties for indexes and preventing duplicates are specified correctly.

All foreign keys and relationships are specified correctly, with the correct specification for referential integrity. The relationship diagram you create in Access is clear and easy to read. (Place a printout of this diagram in your project portfolio.)

All field properties are specified correctly to enforce business rules. Field properties are also consistent in the way items such as field size, dates, currency, and so on are specified for similar items. Student Resource 9.11, Culminating Project Work: Setting Field Properties and Enforcing Business Rules, is complete and ready to be submitted as part of your assessment package.

The final version of your relational database has the most recent version of all tables; the file is named correctly according to your teacher’s instructions; and your teacher has access to it.

All client data has been entered into the correct tables and columns in your database, without errors.

Copyright © 2009–2014 NAF. All rights reserved.

Page 5: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Student Resource 9.3

Reference: Naming Conventions

Table NamesThe following guidelines apply to the names of the physical tables representing entities.

General Guidelines for Table NamesDifferent organizations and database products have different table naming conventions, and you need to ask what the local conventions are wherever you work.

In general, the following guidelines are considered best practices across most of the popular database and operating system environments, including Microsoft Access on Windows or Mac:

As you establish your own table naming conventions (often called local conventions), be consistent across a given database and across related databases.

Use table names that are based on the name of the entity they represent. They should be descriptive, readable, and concise.

Examples: You can use CUSTOMER, order, OrderDetail, and Shipper.

Use abbreviations when necessary to shorten entity names that are longer than the standard maximum length (30 characters). Always use standard abbreviations.

Example: CUSTOMER_ACCOUNT_TRANSACTION could be abbreviated to CUSTOMER_ACCT_TXN.

Use case consistently. You can use all uppercase letters (for example, CUSTOMER), all lowercase letters (for example, customer), or all mixed case (for example, Customer).

Access running on Windows or Mac is a case-sensitive environment (that is, it recognizes that Customer is not the same as CUSTOMER), but in some older database environments, this might not be true. If in the future you are working in a different database and operating system environment, you might need to change your table naming conventions.

Examples: In a given database, you can use the combination of CUSTOMER, SHIPPER, and ORDER, but not the combination of CUSTOMER, Shipper, and order.

Use singular names consistently in all entities in a database. A very common professional standard for table names is that they must be singular and refer to a single instance of the table.

Example: Use Customer instead of Customers, Account instead of Accounts, Order_Detail instead of Order_Details, Shipper instead of Shippers.

Do not put spaces in your table names.

Example: Do not use ORDER DETAIL or Stock Number. If you want to separate parts of names containing two words or long words, use the underscore

(_).

Example: Use Order_Detail, order_detail, and Stock_Number.

Use alphanumeric names (that is, names with only alphabetic or numeric characters). Avoid special characters, except for the underscore (_).

This means that you should not use quotation marks (" or '), forward slashes (/), backslashes (\), pound or number signs (#), less-than symbols (<), greater-than symbols (>), asterisks (*), pipes (|), colons (:), tildes (~), parentheses (()), or the dollar sign ($).

Copyright © 2009–2014 NAF. All rights reserved.

Page 6: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Examples: Do not use $PRICE, Product#, or Supplier:Name.

Begin each entity name with a letter, not a number.

Example: Use PHONE2 but not 2PHONE.

Avoid using special database-related words (often called reserved words) like entity, table, column, field, or file in table names.

This limitation would also include names related to Structured Query Language (SQL), the language that many database management systems, including Microsoft Access, use to query and manage databases. You have not learned about SQL in this course, but some SQL-related names to avoid would be create, select, insert, and delete.

Microsoft Access Rules for Table NamesAccess rejects table names that violate the following rules:

Table names cannot be longer than 255 characters.

Table names cannot have periods (.), question marks (?), exclamation marks (!), square brackets ([ or ]), back quotes (also called accent grave) (`), leading spaces, and nonprintable characters.

All tables in a given database must have unique names.

Column (Field) NamesThe following guidelines apply to the names of the physical columns (also called fields) representing attributes.

General Guidelines for Column (Field) NamesDifferent organizations and database products have different column naming conventions, and you need to ask what the local naming conventions are wherever you work.

In general, the table naming conventions above also apply to column names.

In addition, the following guidelines are considered best practices across most of the popular database and operating system environments, including Microsoft Access on Windows or Mac:

Avoid putting the table name in the column name, except for primary and foreign keys.

Examples: In a table named Shipper, Shipper_ID would be okay, but Shipper_Phone_Number should simply be Phone_Number.

Most column naming standards require that the name end with a class word, which is a classifier of the type of data the column holds. For example, instead of naming a column Phone, you have to choose a name ending with a classifier word like Number, which makes it Phone_Number. Other class words include Name, Date, Amount, Count, Text, Description, Percent, Code, ID, Rate, and Price. Instead of naming an attribute Price, use Item_Price, Unit_Price, and so on. Single-word column names should not be the norm.

Use consistent names for all columns in a table.

Examples: In a given table, use the column naming combination stock_number, price, and units_in_stock, but not stock_number, PRICE, and UnitsInStock.

In general, foreign keys should have the same name as their primary keys.

Example: If you have a primary key column named PRODUCT_ID, do not name your foreign key that points to it MERCHANDISE_ID.

Copyright © 2009–2014 NAF. All rights reserved.

Page 7: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Microsoft Access Rules for Column (Field) NamesMicrosoft Access allows column names up to 64 characters.

You cannot use periods (.), exclamation marks (!), square brackets ([ or ]), back quotes (also called accent grave) (`), leading spaces, and nonprintable characters in column names.

Do not use the word name all by itself as a column name, because it is an Access reserved word. You can, however, use words like First_Name or Last_Name.

Copyright © 2009–2014 NAF. All rights reserved.

Page 8: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Student Resource 9.4

Note Taking: Data IntegrityStudent Name:______________________________________________________ Date:___________

Directions: Use this page to take notes during the presentation on data integrity. Answer each question as you go through the slides.

1. What are the physical database terms for the following?

a. Entity:

b. Attribute:

c. Instance:

2. Write one or two sentences to compare and contrast data integrity and personal integrity.

3. What does entity integrity check for? How does Access check for this?

4. What’s different about entity integrity when you have a composite primary key?

5. What does referential integrity check for? How does Access know to check this?

6. What do we mean when we say that a foreign key is an orphan?

7. Why are Cascade Update and Cascade Delete dangerous?

Copyright © 2009–2014 NAF. All rights reserved.

Page 9: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Student Resource 9.5

Reading: Data Integrity

This presentation provides the following:

• An overview of data integrity and the different types of data integrity

• Examples of how Microsoft Access enforces data integrity

• Example problems involving data integrity

Copyright © 2009–2014 NAF. All rights reserved.

Page 10: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

The physical design of a database (also called a physical model) focuses on its physical components.

In physical design, entities are called tables, and attributes are called columns or fields.

The data for a given entity is called a row or record.

In the example, the table is Customers, and the columns (or fields) are the same as the attributes.

A row in the Customers table has data like “Vanegas, Marlene,” and “362 W. 182 Ave.”

Copyright © 2009–2014 NAF. All rights reserved.

Page 11: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

It is very important that the data in the relational database be accurate, valid, and consistent. As you can imagine, there are many mechanisms in Microsoft Access to help ensure that this is true. Clients would not be happy if their customer data got deleted or messed up in some way!

Data integrity is explained more in the following slides.

Copyright © 2009–2014 NAF. All rights reserved.

Page 12: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

You have probably heard the word integrity in English. A person who has integrity is thought to be honest and straightforward. That person is widely admired for his or her positive qualities.

Data integrity indicates the same kinds of qualities for a database: the database management system includes features that help make sure that data is not lost and relationships are maintained.

Copyright © 2009–2014 NAF. All rights reserved.

Page 13: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

In Access, any time you designate a table field of type AutoNumber as a primary key, an index for the field with No Duplicates specified will also be created.

This prevents you from entering duplicate values for such a field in any table record. It helps establish and maintain entity integrity.

If you tried to enter a second “customer 3” (Orlando Garcia) in the Customers table, Access would refuse to accept your input.

You could have duplicate data in other columns. Suppose there were two people by the same name living in the same household. Everything about them in the sample table would be the same except their customer ID. It is the one thing in the record that makes them unique in this database.

Copyright © 2009–2014 NAF. All rights reserved.

Page 14: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Access automatically creates an index for every column that you designate as a primary key and specifies that there cannot be any duplicate entries. The index is a fast way for the DBMS to search through the database, identify an entry as a duplicate, and reject it.

Copyright © 2009–2014 NAF. All rights reserved.

Page 15: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

To create a composite primary key, select the two fields that will make up the primary key (click to the left of the top field and pull down to include the bottom field), and then click Design > Primary Key. The PK icon appears to the left of both fields.

Copyright © 2009–2014 NAF. All rights reserved.

Page 16: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

If you have a composite primary key OrderID and ProductID, you might have the same ProductID many times in a table. But you will never have two records that both have the same OrderID and the same ProductID.

Copyright © 2009–2014 NAF. All rights reserved.

Page 17: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Referential integrity checks to make sure you don’t have a foreign key in one table that no longer refers to a primary key in another table.

Copyright © 2009–2014 NAF. All rights reserved.

Page 18: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

As you have seen, entity integrity relates to primary keys, and it is automatically enforced in Access.

Referential integrity relates to foreign keys, and like foreign keys, it deals with relationships.

This slide and the next explain how orphan records might occur, why they are a problem in databases, and how to prevent them by asking Access to enforce referential integrity in related tables. Enforcing referential integrity prevents accidentally removing data.

Orphan records are somewhat like orphan children: they no longer have a parent.

Copyright © 2009–2014 NAF. All rights reserved.

Page 19: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

With referential integrity in force, Access will not let you delete the record for Speedy Delivery in the Shippers table.

Copyright © 2009–2014 NAF. All rights reserved.

Page 20: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

When you create a relationship between tables, Access prompts you with the Edit Relationships dialog box. Select the radio button if you want referential integrity enforced.

Copyright © 2009–2014 NAF. All rights reserved.

Page 21: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Access will warn you before it deletes data. It will tell you how many child records will also be deleted. But this is very risky.

Copyright © 2009–2014 NAF. All rights reserved.

Page 22: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

It is a good practice to delete or update data manually instead of using cascading delete and cascading update. You can still delete the child records manually and then delete the shipper, if that is what you want to do. In that case, you don’t need to turn on cascading delete.

Copyright © 2009–2014 NAF. All rights reserved.

Page 23: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

The data in a database is useful only if it has integrity. Entity integrity and referential integrity ensure data integrity and are critical to client satisfaction with a database.

Copyright © 2009–2014 NAF. All rights reserved.

Page 24: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Student Resource 9.6

Defining Format: Data IntegrityStudent Name:______________________________________________________ Date:___________

Directions: Fill in the Defining Format table below to organize the information you know about the terms relating to data integrity. Parts of two definitions have already been supplied.

Term Category Characteristics

Data integrity is a set of rules and checks that

1. ensures all data entered in a database is valid.

2.

3.

A constraint is ________________

________________that

1.

2.

3.

An index is a structure that 1. improves the speed of database lookup operations.

2.

3.

Referential integrity

is ________________

________________that

1.

2.

3.

A primary key constraint

is ________________

________________that

1.

2.

3.

Copyright © 2009–2014 NAF. All rights reserved.

Page 25: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Student Resource 9.7

Tutorial: Using the Relationship Tool to Specify Foreign Keys in Access

You have created your DolphinDemo database and all its tables. The last task you need to do is to set up the relationships between the tables using foreign keys. This guide explains how to use the Relationships tool to do that.

Specifying Foreign Keys1. Open Access and the DolphinDemo database.

2. Be sure none of the tables are open.

3. Click Database Tools > Relationships. The Show Table dialog box opens.

4. Select all the tables in the DolphinDemo database, and click Add.

5. Close the Show Table dialog box.

6. It is often easier to rearrange the table icons as you work. Refer to the following diagram and organize your table icons accordingly. To do the foreign key operation, you need to drag using the mouse from the “one” table to the “many” table. The order you do the operations is somewhat arbitrary, but do the junction table (OrderDetails) last.

Copyright © 2009–2014 NAF. All rights reserved.

Page 26: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

7. First, connect the Customers table to the Orders table. The connection is from field CustomerID (the primary key) in Customers to CustomerID (the foreign key) in Orders. Customers is the “one” table, and Orders is the “many” table.

Click CustomerID in the Customers table and drag it to CustomerID in the Orders table (be sure you are pointed directly at the name, as shown in the following diagram). Note that you need to click and drag from the right side of the field name, even if you’re dragging to a table icon to your left.

The Edit Relationships dialog box appears.

8. Be sure CustomerID is shown in both text boxes.

Copyright © 2009–2014 NAF. All rights reserved.

Page 27: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

9. Select Enforce Referential Integrity. (Do not select the Cascade Update or Cascade Delete check boxes.)

10. Click Create.

11. Check to be sure the relationship has been established as shown in the following diagram.

Copyright © 2009–2014 NAF. All rights reserved.

Page 28: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

12. Repeat steps 7–11 for the relationship between Shippers and Orders. The “one” table is Shippers (with PK ShipperID), and the “many” table is Orders (with FK ShipperID).

13. Repeat steps 7–11 for the relationship between Categories and Products. The “one” table is Categories (with PK CategoryID), and the “many” table is Products (with FK CategoryID).

14. Repeat steps 7–11 for the relationship between Suppliers and Products. The “one” table is Suppliers (with PK SupplierID), and the “many” table is Products (with FK SupplierID).

15. Repeat steps 7–11 for the relationship between Orders and OrderDetails. The “one” table is Orders (with PK OrderID), and the “many” table is OrderDetails (with part of the composite PK and now also FK OrderID).

16. Repeat steps 7–11 for the relationship between Products and OrderDetails. The “one” table is Products (with PK ProductID), and the “many” table is ProductDetails (with part of the composite PK and now also FK ProductID).

Your final relationships should look like the following diagram.

Copyright © 2009–2014 NAF. All rights reserved.

Page 29: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

17. Save your relationship diagram and close it.

Copyright © 2009–2014 NAF. All rights reserved.

Page 30: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Student Resource 9.8

Procedural Steps: Setting Up Keys and Relationships in Access

Directions: Working in your culminating project group using Microsoft Access, follow the procedural steps listed below to create (and verify) the primary keys, foreign keys, and relationships for your culminating project database. Use your notes from the presentation and Student Resource 9.5, Reading: Data Integrity, along with the procedure outlined in the tutorial (Student Resource 9.7, Tutorial: Using the Relationship Tool to Specify Foreign Keys in Access), to help you do this work correctly. Before you begin your work, make sure you understand the assessment criteria in the rubric for this part of your project.

Use the following checklist to check off each part of the procedure as you complete it:

For each table in your database, specify the primary key (or composite primary key) correctly with indexes and no duplicates, as required.

Make sure all foreign keys appear in the tables where they are required.

Working as a group, use the Access Relationships tool to set up relationships, verifying that pointers to foreign keys and the types of relationships (one-to-many, and so on) are correct. Specify referential integrity when there are foreign keys.

In the Relationships tool, move the tables around so that the diagram is easy to read and lines are not crossing. Print out the relationships diagram.

To check your work, have one group member read through the diagram, explaining each relationship and the keys in each relationship. Other group members should ask questions and agree or disagree with each relationship that is read. Make any required changes to your relationships diagram, and print a final version of it.

Put a printed version of your final relationships diagram in your portfolio. You will be submitting this to your teacher as part of your assessment package.

Copyright © 2009–2014 NAF. All rights reserved.

Page 31: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Student Resource 9.9

Worksheet: Validation RulesStudent Name:______________________________________________________ Date:___________

Directions: Work through the exercises on this worksheet as you read the Access Help file about validation rules. This worksheet refers to Access 2013. If you are working with an earlier version of Access, there are minor changes to Access Help. Ask your teacher for assistance.

To access the help file about validation rules, follow these steps:

1. Press F1 to display Access Help.

2. On the home page of Access Help, type validation rule in the search field and click the search button.

3. Select the first article, “Restrict Data Input by Using a Validation Rule.”

Read the following two sections of this help page, and do the numbered exercises on this worksheet as you read them:

Understand validation rules

Validate data during entry in table fields

1. Below is a list of the different validation methods that help to ensure users enter data properly. Explain how each method validates data, and give an example of each. If possible, use examples from your culminating project database.

Data types:

Example:

Field size:

Example:

Table properties (or field properties):

Example:

Copyright © 2009–2014 NAF. All rights reserved.

Page 32: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Input masks:

Example:

2. What is the difference between a field validation rule and a record (or table) validation rule?

3. Label the following validation rules as field validation rules or record validation rules, and explain what each rule does. The first one is done for you as an example:

Validation Rule Type of Rule Explanation

>=#01/01/2013# Field validation Requires the user to enter a date on or after January 1, 2013

[ShipDate]<=[OrderDate]+30

>10

>=0

4. Using the dolphin database, follow the instructions in the section of Access Help titled “Validate data during entry in table fields” to create the following validation rules:

In the Order Details table, create a field rule to validate that the quantity of items ordered is greater than 3. In the screenshot below, write what you wrote in the database file.

Copyright © 2009–2014 NAF. All rights reserved.

Page 33: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

In the Orders table, create a table rule to validate that the ship date is no more than 3 days after the order date. In the screenshot below, write what you wrote in the database file.

When you test the validation rules using the procedure in the help file, what message do you get?

Copyright © 2009–2014 NAF. All rights reserved.

Page 34: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Student Resource 9.10

Reference: Syntax for Common Validation RulesHere are some syntax tips for your validation rules:

Surround the names of table fields with square brackets, like so: [RequiredDate]<=[OrderDate]+30.

Surround dates with pound signs (#), like so: <#01/01/2013#.

Surround text values with double quotation marks, like so: IN ("Tokyo","Paris","Moscow"). Also, note that you separate items with commas, and you place lists inside parentheses.

Expression Description Example Your Example

NOT Tests for converse values. Use before any comparison operator except IS NOT NULL.

NOT > 10 (the same as <=10)

IN Tests for values equal to existing members in a list. Comparison value must be a comma-separated list enclosed in parentheses.

IN ("Tokyo","Paris","Moscow")

BETWEEN Tests for a range of values. You must use two comparison values—low and high—and you must separate those values with the AND separator.

BETWEEN 100 AND 1000 (the same as >=100 AND <=1000)

LIKE Matches pattern strings in Text and Memo fields. LIKE "Geo*"

IS NOT NULL

Forces users to enter values in the field. This is the same as setting the Required field property to Yes. However, when you enable the Required property and a user fails to enter a value, Access displays a somewhat unfriendly error message. Typically, your database is easier to use if you use IS NOT NULL and enter a friendly message in the Validation Text property.

IS NOT NULL

Copyright © 2009–2014 NAF. All rights reserved.

Page 35: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Expression Description Example Your Example

AND Tests that the condition that comes before it in the rule AND the condition that follows it in the rule are both met.

>= #01/01/2013# AND <=#03/06/2014#

You can also use AND to combine validation rules. For example: NOT "UK" AND LIKE "U*".

OR Tests that either the condition that comes before it in the rule OR the condition that follows it in the rule is met, but both are not required.

January OR February

< Less than.

<= Less than or equal to.

> Greater than.

>= Greater than or equal to.

= Equal to.

<> Not equal to.

Copyright © 2009–2014 NAF. All rights reserved.

Page 36: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Student Resource 9.11

Culminating Project Work: Setting Field Properties and Enforcing Business Rules

Student Names:__________________________________________________ Date:_______________

Directions: Using all of the information you have gathered from your client and all you know about check constraints and validation rules, follow the steps on this worksheet to set field properties and enforce business rules for your culminating project database. You must submit this worksheet as part of your project package.

1. Working as a group, use the table below to set up some general rules about what you want your data to look like. Then use the information in this table to make sure you use the agreed-upon format for all field properties that you set. Use the following questions to guide you. You may come up with more items as you work through your client database.

a. Are there any columns where you want to limit the field size to make sure users don’t enter data that doesn’t make sense?

b. Do you want to specify a special format for entering phone numbers?

c. What information do you want in date fields?

d. Do you want to make sure that users enter only US currency in the currency field?

e. Are there any fields that will often have the same value, and where you can enter a default value?

Field Property Notes

Field size limitations

Date format

Currency format

Default values

Copyright © 2009–2014 NAF. All rights reserved.

Page 37: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

2. Work as a group to write all the business rules for your database in the left column of the following table. Start with the business rules in your project description document, and then add other business rules that you have discovered during your work on the database. (There may be some things that you didn’t originally realize were business rules.) Make this list as complete as you possibly can.

3. Assign each business rule to a group member, and work independently to fill in the columns to explain how you would enforce the business rule in Access. If you have a business rule that cannot be enforced using field properties, make a special note across all columns of how you will enforce that business rule.

This sample is provided to give you an idea of what kinds of information to put in your table:

Business Rule Table and Columns

Field Property Constraints

Validation Rule

Validation Text

All customers must reside in the United States and have a valid US address.

Customer – State

Customer – ZIP

Required: Yes

Required: Yes

No more than 15 units of an item can be in stock.

Products – Units_in_Stock

<16 Cannot have more than 15 of this item in stock

Business RuleTable and Columns

Field Property Constraints

Validation Rule Validation Text

Copyright © 2009–2014 NAF. All rights reserved.

Page 38: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Business RuleTable and Columns

Field Property Constraints

Validation Rule Validation Text

4. When you have completed the table, have members take turns explaining to the other group members how they would enforce the business rules assigned to them, and have group members ask questions and make corrections as needed.

5. When you have come to agreement on how to enforce each business rule, highlight all of the tables that need to be updated (in the “Tables and Columns” column).

6. Assign each table to a group member. Working in Access, update the tables assigned to you, specifying the file size and formats you agreed on in the first table of the exercise, along with the field properties and validation rules you have decided on to enforce your business rules.

7. After each table is updated, manually enter test data into the table until you know the rules are working correctly. Enter the kind of data you think you might get from your client. Make necessary changes to any rules that didn’t work like you expected. Making all corrections now will save you trouble when you import your client’s data.

Copyright © 2009–2014 NAF. All rights reserved.

Page 39: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Student Resource 9.12

Tutorial: Importing Data Using the Import WizardDirections: Follow your teacher’s instructions to work through this tutorial.

If you have data in any of the following formats, you may be able to use the Import Wizard to import the data into an Access table:

Data in another table in the same Access database Data in a table in another Access database Data in an Excel spreadsheet Data in a flat file (for example, a tab-delimited text file)

You can import an entire table or file, or you can just import some of the columns.

Preparing Your Data for ImportFirst, check to make sure the data you want to import meets the following criteria. If it doesn’t, you will have to work with your data before you import it.

The first row in the source file (for example, the Excel file that you get from your client) must contain column headers that match the field (column) names in the target Access table. If the names of any of the columns in your source file don’t match the column names in your Access file, you need to change the names of the columns in your source file.

The data in each column of your source file must be an appropriate match for the data type in the target Access table. If you discover that you have a data type that doesn’t match the data, you need to either change the data type or change the client data to match the data type before you do the import.

If your source data doesn’t match the columns in your Access table because it has two fields in one column (for example, first and last name, or city and state), you will have to separate them into two columns before you import your data.

If your source data has an inconsistent format or data type (for example, a set of identifiers, some of which are text and some of which are integers), you need to change the data so that it is consistent before you import it.

If you have source data that is not formatted as a selectable column or that cannot be converted to a selectable column (for example, data in paragraph format), you will have to put it into column format before you can import it.

If you are using automatically numbered (AutoNumber) primary keys, do not import data for this field; Access will do the numbering and fill in this field as soon as you import data into the other fields.

Importing Data from an Excel SpreadsheetIn this practice exercise, you will import data from an Excel spreadsheet (Categories.xls) to the Categories table in the DolphinDemo database. All the prep work has been done for you; the data in the spreadsheet is in exactly the same order and format as the blank Categories table.

1. Be sure you have access to Categories.xls.

2. Open Access and the DolphinDemo database. Be sure the Categories table is not open.

3. Choose External Data > Excel. The Get External Data – Excel Spreadsheet window opens.

Copyright © 2009–2014 NAF. All rights reserved.

Page 40: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

4. Browse for the Categories.xls file, and select the radio button “Append a copy of the records to the table.”

5. Be sure the Categories table has been selected in the drop-down list.

6. Click OK.

The Import Spreadsheet Wizard opens.

Copyright © 2009–2014 NAF. All rights reserved.

Page 41: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Notice that Access has already attached the appropriate column (field) names to the data in the spreadsheet.

7. Click Next.

The Import Spreadsheet Wizard indicates it has enough information to import your Excel data into Access.

8. Do not indicate that you would like Access to analyze your table after importing the data.

9. Click Finish.

10. Do not save the import steps.

11. Click Close. When you finish an import operation, be sure to check the result carefully before you save the table or database.

12. Open the Categories table. Your imported data should appear in Datasheet View.

Copyright © 2009–2014 NAF. All rights reserved.

Page 42: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

13. Switch to Design View. Notice that your design is exactly as it was prior to the import operation.

Importing Data from a Text File1. Be sure you have access to Suppliers.txt.

2. Open Access and the DolphinDemo database. Be sure the Suppliers table is not open.

3. Choose External Data > Text File. The Get External Data – Text File window opens.

4. Browse for the Suppliers.txt file.

5. Select the radio button “Append a copy of the records to the table” and select Suppliers from the drop-down list.

6. Click OK. The Import Text Wizard opens.

Copyright © 2009–2014 NAF. All rights reserved.

Page 43: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

The wizard notices that your data is in a delimited format. It will confirm what delimits the data in the next screen.

7. Click Next.

The wizard correctly guesses that the delimiter is a tab character. The column (field) names are correct.

8. Select the First Row Contains Field Names check box.

9. Click Next.

10. Click Finish.

11. Click Close.

12. Check the data in the Suppliers table. As you will see, a lot of the data in the table is still missing (it may need to be entered manually), but the text file data should have imported okay.

Copyright © 2009–2014 NAF. All rights reserved.

Page 44: Lesson 16curriculum.naf.org/packaged/assets/downloads...  · Web viewAOIT Database Design. Lesson 9 . Creating a Relational Database. AOIT Database Design. Lesson 9 . Creating a

AOIT Database DesignLesson 9 Creating a Relational Database

Copyright © 2009–2014 NAF. All rights reserved.