0% found this document useful (0 votes)
3 views

lab 3

This lab introduces students to designing and managing relational databases using MS Access, focusing on creating related tables, defining relationships, and enforcing referential integrity. Students will learn to enter data, run queries, create forms, and generate reports, culminating in a lab assignment to build a customer order management database. Key concepts include primary and foreign keys, and the importance of referential integrity in maintaining data consistency.

Uploaded by

Aziz ul haq
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

lab 3

This lab introduces students to designing and managing relational databases using MS Access, focusing on creating related tables, defining relationships, and enforcing referential integrity. Students will learn to enter data, run queries, create forms, and generate reports, culminating in a lab assignment to build a customer order management database. Key concepts include primary and foreign keys, and the importance of referential integrity in maintaining data consistency.

Uploaded by

Aziz ul haq
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Lab 4: Designing and Managing Relational Databases in MS Access

Objective:
The purpose of this lab is to introduce students to relational databases and the concept of
relationships between tables in MS Access. By the end of this lab, students will understand how
to create multiple related tables, define relationships, enforce referential integrity, and run
queries that span multiple tables.

Chapter Overview
1. Introduction to Relational Databases

A relational database organizes data into tables (also called relations) that can be linked together
based on shared data fields. This allows for efficient management of data without redundancy. In
a business context, relational databases are essential for managing complex data, such as customer
orders, employee records, and inventory.

Key Concepts:

• Primary Key: A unique identifier for each record in a table.


• Foreign Key: A field in one table that uniquely identifies a row of another table, creating
a relationship between them.
• Referential Integrity: A set of rules that Access enforces to maintain consistency
between related tables.

Step-by-Step Execution of Tasks


Task 1: Create Multiple Related Tables

1. Creating the Database:


o Open MS Access and create a new database called
Company_RelationalDB.accdb.
2. Creating the First Table (Employees Table):
o Go to Create → Table Design.
o Define the fields for the Employees table as follows:

Field Name Data Type Description


Employee ID AutoNumber Primary Key
Employee Name Short Text Name of the employee
Department of the
Department Short Text
employee
Hire Date Date/Time Date of hiring
Salary Currency Employee's salary
• Set Employee ID as the primary key.
• Save the table as Employees.

3. Creating the Second Table (Departments Table):


o Create a second table named Departments with the following fields:

Field Name Data Type Description


Department ID AutoNumber Primary Key
Department Name Short Text Name of the department
Manager ID Number Foreign Key (References Employees)

• Set Department ID as the primary key.


• Save the table as Departments.

4. Creating the Third Table (Projects Table):


o Create a third table named Projects with the following fields:

Field Name Data Type Description


Project ID AutoNumber Primary Key
Project Name Short Text Name of the project
Department ID Number Foreign Key (References Departments)
Start Date Date/Time Project start date

• Set Project ID as the primary key.


• Save the table as Projects.

Task 2: Defining Relationships Between Tables

1. Creating Relationships:
o Go to the Database Tools tab and click on Relationships.
o Add the Employees, Departments, and Projects tables to the relationships
window.
2. Linking Tables:
o Drag Department ID from the Departments table to Department ID in the
Projects table. This creates a relationship between departments and projects.
o Drag Manager ID from the Departments table to Employee ID in the
Employees table. This links each department to a manager.
o Select Enforce Referential Integrity and Cascade Update Related Fields to
ensure data consistency.
3. Saving Relationships:
o Save the relationships once they are established.
Task 3: Entering Data into Related Tables

1. Entering Data for Employees Table:


o Switch to Datasheet View for the Employees table and enter the following data:

Employee ID Employee Name Department Hire Date Salary


1 John Doe Sales 2020-01-15 $50,000
2 Jane Smith Marketing 2019-03-10 $60,000
3 Mike Brown HR 2021-06-05 $45,000

2. Entering Data for Departments Table:


o In the Departments table, enter the following data:

Department ID Department Name Manager ID


1 Sales 1
2 Marketing 2
3 HR 3

3. Entering Data for Projects Table:


o In the Projects table, enter the following data:

Project ID Project Name Department ID Start Date


1 New Product Launch 1 2023-05-01
2 Marketing Strategy 2 2023-04-15

Task 4: Running Queries on Related Tables

1. Creating a Query with Related Tables:


o Go to the Create tab and select Query Design.
o Add the Employees and Departments tables to the query.
o Drag Employee Name, Department, and Salary fields from the Employees
table and Department Name from the Departments table.
2. Filtering Data in the Query:
o Set a criteria to show only employees in the Sales department.
o Run the query to see a list of employees in the Sales department along with their
salaries and department names.
3. Saving the Query:
o Save the query as Sales Department Employee Query.

Task 5: Creating Forms for Related Data Entry

1. Creating a Form with Subform:


o Go to Create → Form Wizard.
o Select Departments as the main table and Projects as the subform.
o Follow the wizard to design a form that allows users to enter department
information along with associated projects.
2. Navigating the Form:
o Use the form to navigate between departments and view/edit the projects linked to
each department.
3. Saving the Form:
o Save the form as Department and Projects Form.

Task 6: Generating Reports from Related Data

1. Creating a Report:
o Use the Report Wizard to create a report based on the Projects table.
o Add fields such as Project Name, Department ID, and Start Date to the report.
2. Customizing the Report:
o In Design View, you can adjust the layout, add a title, and group the data by
Department ID to create a more structured report.
3. Saving and Printing the Report:
o Save the report as Projects by Department Report and print it if needed.

Discussion Questions:
1. Why is referential integrity important in relational databases? Discuss how enforcing
referential integrity helps ensure data accuracy and consistency across related tables.
2. How can relationships between tables simplify complex data structures in business
environments? Explore how relational databases reduce data redundancy and improve
data organization.
3. What are the advantages of using queries to extract data from multiple tables?
Discuss how queries that span multiple tables help managers gain insights into
interconnected datasets.

Lab Assignment:

• Assignment Task:
Create a database for managing customer orders. Include the following tables:
o Customers Table: Fields for Customer ID, Name, Contact Info.
o Orders Table: Fields for Order ID, Customer ID (Foreign Key), Order Date, and
Total Amount.
o Products Table: Fields for Product ID, Product Name, Price.
o Define relationships between the tables.
o Populate the tables with sample data.
o Create a query to list all orders placed by a specific customer.
o Design a form for entering new customer orders.
o Generate a report that shows all orders and their total amount, grouped by
customer.
• Submission:
Submit your Access database file through the learning management system.

Key Takeaways:

• Relational databases provide a powerful way to manage complex data by linking tables
through relationships.
• Referential integrity ensures that relationships between tables remain valid and
consistent.
• Forms, queries, and reports are essential tools for interacting with and presenting
relational data in business environments.

You might also like