Reading history

Database Basics and MS Access

5 min read 0 views

Learn databases and DBMS, tables, records, fields and data types, primary and foreign keys, relationships, and queries, forms and reports in MS Access.

Your school keeps records of thousands of students: names, rolls, classes, marks and fees. A bank keeps millions of accounts. Keeping all that in a single spreadsheet soon becomes a mess of repeated and mistyped data. A database stores it in an organised way, so it can be searched, updated and reported on safely. In this lesson you will learn the key database terms and how to build tables, relationships, queries, forms and reports in Microsoft Access.

In this lesson you will learn

  • What a database and a DBMS are
  • Tables, records, fields and data types
  • Primary keys, foreign keys and relationships
  • How to find data with queries
  • What forms and reports are for

You should know spreadsheet basics.

Databases and DBMS

A database is an organised collection of related data. A database management system (DBMS) is the software that creates the database and lets people add, change, search and protect the data. Microsoft Access is a DBMS for small offices and classrooms. Large systems use DBMSs such as MySQL, PostgreSQL, Oracle or SQL Server.

Why not just use a spreadsheet?

  • Less repetition: a student’s address is stored once, not on every marks sheet.
  • Fewer errors: rules can stop wrong data, such as a mark of 150 out of 100.
  • Many users: several people can work on the data at once.
  • Security: different users can be given different permissions.

Tables, Records and Fields

A database stores data in tables. Each row is a record: everything about one student. Each column is a field: one piece of information, such as Name or Class.

Every field has a data type. In Access the main ones are:

Data typeStoresExample
Short TextWords or codes up to 255 charactersName, Phone
NumberNumbers used in calculationsMarks
Date/TimeDates and timesDate of birth
CurrencyMoney valuesFee
Yes/NoTrue or falseFee paid?
AutoNumberA number Access fills in automaticallyRecord ID

Store phone numbers as Short Text, not Number. They are not used in sums, and a Number field would drop the leading 0 of 01711…

Keys and Relationships

A primary key is a field whose value is different for every record, so it identifies the record exactly. A student ID is a good primary key; a name is not, because two students can share a name.

A foreign key is a field in one table that holds the primary key of another table. It links the two tables.

StudentsStudentIDPKNameClassPhoneResultsResultIDPKStudentIDFKSubjectMarks1∞one student → many resultsPK = primary key (unique in its table)FK = foreign key (points to a primary key)

In the figure, one student can have many results, but each result belongs to one student. This is a one-to-many relationship. Other types are one-to-one (each student has one library card) and many-to-many (students and clubs), which is usually split into two one-to-many links through a middle table.

In Access, open Database Tools → Relationships and drag the primary key onto the matching foreign key. Tick Enforce Referential Integrity. Access will then refuse a result for a student ID that does not exist.

Queries

A query asks the database a question and shows only the matching data. In Access you build one in Query Design: choose the tables, drag in the fields you want, and type criteria.

Show students in Class 10 who scored 80 or more in ICT

Field:     Name      Class    Subject    Marks
Table:     Students  Students Results    Results
Criteria:            10       "ICT"      >=80
Sort:                                    Descending

Behind the scenes, Access turns this into SQL, the standard language for databases:

SELECT Name, Class, Subject, Marks
FROM Students INNER JOIN Results ON Students.StudentID = Results.StudentID
WHERE Class = 10 AND Subject = "ICT" AND Marks >= 80
ORDER BY Marks DESC;

You can learn more in our lessons on the SQL WHERE clause and SQL joins.

Forms and Reports

  • A form is a friendly screen for entering or viewing one record at a time, with labelled boxes and buttons. Office staff use forms so they never have to touch the raw tables.
  • A report is a formatted page for printing or sharing, such as a class result sheet grouped by section with totals and averages.

Common Mistakes

  1. Using a name as the primary key. Names repeat; use a unique ID.
  2. Storing the same data in many tables. Store it once and link with keys.
  3. Choosing Number for phone numbers or roll codes. Use Short Text for codes that are not calculated.
  4. Putting several values in one field. “Math, ICT, Physics” in one cell is hard to search; use separate records.

Practice Exercises

Exercise 1. A Books table has the fields BookID, Title, Author and Price. Which field should be the primary key, and what data type suits Price?

Show answer

BookID should be the primary key, because it is unique for each book. Price should be Currency.

Exercise 2. A library lends books to members. One member can borrow many books over time. Which table should hold the foreign key, Members or Loans?

Show answer

Loans. Each loan record holds the MemberID of the member who borrowed the book, linking it to the Members table.

Exercise 3. Write the query criteria to show products whose price is between 100 and 500 taka.

Show answer

In the Price column: Between 100 And 500 (or >=100 And <=500).

Frequently Asked Questions

What is the difference between a primary key and a foreign key?

A primary key uniquely identifies each record in its own table, such as StudentID in the Students table. A foreign key is a field in another table that stores that primary key value, linking the two tables together.

What is a query in MS Access?

A query is a saved question that picks out the records and fields you need, using criteria such as Marks greater than or equal to 80. It can also sort data, combine tables and calculate totals.

Summary

  • A database stores organised data; a DBMS such as Access manages it.
  • Tables hold records (rows) and fields (columns), each field with a data type.
  • Primary keys identify records; foreign keys link tables in relationships.
  • Queries find data, forms make data entry easy, and reports present results.

Next: Excel Lookup and Logical Functions.

Lessons are also marked complete when you click Next.

Leave a Reply

Your email address will not be published. Required fields are marked *