Introduction to
Microsoft's Access
by K. Yue
1. Introduction to MS Access
- MS Access is a relational database management system.
- MS Access is a very mature product and there are plenty of tutorials, examples, and resources.
- It is based on the relational model.
- To start, it is necessary to become familiar with the following basic concepts:
- table (or relation): contains rows of information
- row: contains information about a concept, event, object, entity, etc.
- column (or field, attribute) (or a row): stores the value of a property of a row.
- column value
- data type: acceptable values of a column.
- data subtype
- primary key (of a table): a set of columns that uniquely identify a row in a table.
- foreign key (of a table): a column that references a primary key of a referenced table.
- relationship (between relation/table): usually refer to a foreign key referencing a primary key.
- relationship diagram (not to be confused with the entity relationship, or ER, diagram).
- query: an executable solution to a data problem.
- SQL: a standard query language for relational databases.
- As a GUI tool, there are various important views. MS Access includes the followings:
- Datasheet: allows insert/delete/update of individual rows.
- Query: design queries to answer questions using a Query by Example approach (Based on Domain Relational Calculus)
- Design: define tables, columns, keys, constraints, etc.
- There are also numerous database tools, e.g., relationship diagram.
- Our course requires a small percentage of the features provided by MS Access.
- As a starter, make sure you know how to:
- create a table
- populate a table
- create a simple query
- Many features are not covered in Access in this course, such as:
- create forms
- create reports
- Programming in MS Access
- In order to use MS Access, you may:
- Use a computer in the department labs or UHCL labs with MS Access installed.
- Gain MS Access license and install it in your computer. (However, Office 365 via UHCL does not include MS Access)
- Use UHCL virtual lab, Apporto: https://www.uhcl.edu/computing/labs/virtual-lab.
2. Access Architecture
The general database architecture uses a client-server architecture:
- A DB server, S, listens to a port.
- A DB client, C, connects to the DB server and sets up a session.
- C sends a SQL command to S.
- S executes the SQL command and sends the result back to C.
MS Access contains both the DB client and DB server:
- MS Access Users use the Graphical User Interface (GUI) to develop queries.
- SQL commands are generated from the GUI queries.
- SQL commands are executed by the MS Access DB engine.
- Results are displayed in Access GUI.
3. Brief Introduction to the Relational Model
The basic relational data model in layman terms:
- A database is composed of a collection of tables (relations).
- A table contains many rows (tuples, records) and columns (attributes, fields)
- Each row contains many column values.
- Every row of a table has the same columns.
- Values of the same column have the same data type.
- A table has a primary key to uniquely identify a row.
- Data from two tables R1 and R2 can be linked by mean of a foreign key of R1 and a primary key of R2 (known as the parent table).
Example:
Consider toyu.accdb:
The database toyu has eight tables (primary keys are underscored):
- grade(grade, gradePoint)
- school(schoolCode, schoolName)
- department(deptCode, deptName, schoolCode, numStaff)
- faculty(facId, fname, lname, deptCode, rank)
- course(courseId, rubric, number, name, credits)
- class(classId, courseId, semester, year, facId, room)
- student(stuId, fname, lname, major, minor, ach, advisor)
- enroll(stuId, classId, grade, n_alerts)
The student table contains 10 rows at the moment:
Student has seven columns:
Columns should be defined, such as in a data dictionary. For examples, for the table student:
Student: a row in the student table stores the information of a student.
- stuId: a unique id for the student (primary key).
- fname: the first name of the student.
- lname: the last name of the student.
- major: the department code (deptCode) of the major of the student. Major may not be declared, and thus a null value is acceptable.
- minor: the department code (deptCode) of the minor of the student. Minor may not be declared, and thus a null value is acceptable.
- ach: the number of accumulated credit hours, including transferred credits.
- advisor: the faculty id (facId) of the faculty who serves as the advisor of the student. A student may have no faculty advisor.
There are three foreign keys in the student table:
- major references department(deptCode)
- minor references department(deptCode)
- advisor references faculty(facId)
The table faculty:
Classroom exercise:
Provide the data dictionary for the table faculty.
4. Keys
Consider the stuId 100000 in the student table:
(stuId: 100000, fname: 'Tony', lname: 'Hawk', major:'CSCI', minor: 'CINF', credits:40, advisor:1011)
The column 'advisor' is a foreign key in the table student. Its value, 1011, must appear in the column 'facId', which is the primary key of the table faculty (the parent table).
A relationship diagram in Access shows foreign key relationships between tables.
A primary key may be a composite key (containing more than one columns) and a table can have multiple foreign keys.
Classroom Demonstration or Practice Exercise
(1) List the primary keys and foreign keys of all tables.
(2) Insert/Update/Delete
(a) Using toyu.accdb, add a new student:
(stuId: 100100, fname: 'Stephanie', lname: 'Smith', major:'MATH', minor: 'CINF', credits:33, advisor:1012)
(b) Lillian Johnson now has no minor.
(c) The class with id 11004 is canceled and its information should be deleted.
(3) New table: Create a new table Semester with the following columns:
- SemesterId: auto number
- Semester: 30 char string
- Description: 255 char string
Insert the following four rows into the newly created table.
Semester
SemesterId |
Semester |
Description |
1 |
Fall |
Regular Fall semester |
2 |
Spring |
Regular Spring semester |
3 |
Summer |
Regular Summer semester |
4 |
Fall First 8 weeks |
Fall First 8 week semester |
(4) Foreign key:
In the class table, change the data type of "semester" to number. Rename the field to "SemesterId". Replace the field values of "Fall" and "Spring" to 1 and 2 respectively. Create a foreign key for the class table: SemesterId references Semester(SemesterId).
See toyu_withClasswork.accdb
We will demonstrate how to construct queries to satisfy data problems in the class.