One file, several kinds of object
Microsoft Access is a relational database management system. Unlike most, it keeps everything in a single file — the data, the forms, the queries and the reports — which makes it easy to copy and easy to outgrow.
That file contains four kinds of object, and the exam expects the purpose of each. They are not alternatives; a working database uses all four, each doing the job the others cannot.
| Object | Purpose | Holds data? |
|---|---|---|
| Table | stores the data, in rows and columns | yes — the only one that does |
| Query | selects, filters, sorts and calculates | no — it re-reads the tables each time |
| Form | a screen for entering and viewing records | no |
| Report | formatted output designed for printing | no |
| Macro | automates a sequence of actions | no |
Only tables store data
A query holds no data of its own — it stores the question, and answers it afresh from the tables each time it is opened. That is why editing a record through a form updates every query and report that uses it, and why deleting a query never deletes any data. Students routinely write that a query "stores the selected records", which is exactly wrong.
Building a table
A table is defined in Design View, where each field is given a name, a data type and a set of properties. Datasheet View then shows the rows and is where data is actually typed — but it is the design that determines what may be typed at all.
The field properties are where most of the marks are, because they are how integrity rules from the previous chapter are actually enforced.
| Property | Effect |
|---|---|
| Field Size | limits the length of text or the range of a number |
| Format | how the value is displayed, without changing what is stored |
| Input Mask | forces a pattern as the user types, e.g. a CNIC layout |
| Validation Rule | rejects values failing a condition, e.g. >=0 And <=100 |
| Validation Text | the message shown when the rule rejects a value |
| Required | the field may not be left empty |
| Default Value | a value filled in automatically for new records |
| Indexed | speeds up searching and can enforce uniqueness |
A STUDENT table needs a Marks field accepting whole numbers from 0 to 100, which must not be left blank. State the design settings.
- Data Type: Number, Field Size Integer.Arithmetic will be done on marks, and no fractional mark is awarded.
- Validation Rule:
>=0 And <=100.This is the range check, enforced by the DBMS rather than by whoever wrote the data entry form. - Validation Text: "Marks must be between 0 and 100".Without it the user sees a generic error and does not know what to do.
- Required: Yes.This is the presence check. A blank mark is different from a mark of zero, and both must be impossible here.
- Do not set this field as the primary key.Marks are neither unique nor stable — the two things a primary key must be.
Number/Integer, validation rule >=0 And <=100 with a message, and Required set to Yes.
Setting the primary key and the relationships
A table is given a primary key in Design View, and Access will create an AutoNumber field if you do not choose one — a meaningless, automatically incrementing integer, which is usually exactly what a good primary key should be.
Relationships are then defined in the Relationships window by dragging a primary key onto the matching foreign key. Access shows the cardinality it has inferred, and offers to enforce referential integrity. Ticking that box is what stops a record being created with a foreign key matching nothing, and stops a parent record being deleted while children still refer to it.
The Relationships window is this diagram, drawn by dragging. Access infers the cardinality from the keys — one to many appears automatically when the field is a primary key on one side and an ordinary field on the other.
Cascade update and cascade delete
With referential integrity enforced, two further options appear. Cascade Update changes the foreign keys automatically if a primary key changes — rarely needed, since a good primary key never changes. Cascade Delete removes all related child records when a parent is deleted, which is right for a customer's order lines and dangerous for a customer's invoices. Consider what should happen before ticking it.
When Access is the right tool, and when it is not
Access suits a small organisation with a handful of simultaneous users and a database of moderate size. Its advantages are real: forms and reports can be built without programming, everything lives in one file, and it integrates with the rest of the Office suite.
Its limits are equally real. It is designed for a small number of concurrent users and becomes unreliable with many. The single file has a size ceiling. It runs on Windows, not on a phone or a web server. A system that grows beyond those limits moves to a client-server database such as MySQL, SQL Server or PostgreSQL — often keeping the same table design, which is the reward for having designed it properly rather than in the tool.
Before you leave this chapter
- Tables, queries, forms and reports — only tables store data.
- A query stores the question and re-answers it from the tables each time.
- Design View sets field types and properties; Datasheet View shows the rows.
- Validation Rule plus Validation Text is how a range check is actually enforced.
- Enforcing referential integrity is a tickbox; cascade delete needs thinking about first.