Introduction to Databases
Have you ever wondered how your school library keeps track of thousands of books, or how a smartphone stores hundreds of contact names and phone numbers? They don't just throw everything into a giant pile! They use a Database.
In this chapter, we will explore how databases organize information so that we can find what we need in a split second. Think of a database as a highly organized digital filing cabinet.
1. The Basic Building Blocks
To understand a database, we need to look at how it is built. It’s like a set of Russian dolls—one piece fits inside the next. Let's look at the structure from smallest to largest:
A. Field (The Smallest Unit)
A Field is a single piece of information. For example, in a list of students, "First Name" is a field, and "Date of Birth" is another field.
B. Record (A Complete Set)
A Record is a collection of related fields about one person or one thing. If you look at your school ID card, all the information on it (your name, your class, and your student number) together makes up your record.
C. File / Table (The Collection)
A File (often called a Table in database software) is a collection of many records. For example, a file called "S3_Students" would contain the records of every student in Secondary 3.
D. Database (The Whole System)
The Database is the entire system that stores one or more files and allows us to handle the data.
Analogy: Imagine a school yearbook. One person’s phone number is a Field. All the info about that person is a Record. The page for Class 3A is a File. The entire yearbook is the Database.
2. The Primary Key: The Unique ID
In a large database, many people might have the same name (e.g., "Chan Tai Man"). How does the computer know which one is which? We use a Primary Key.
Definition: A Primary Key is a field that is unique to every record. No two records can have the same Primary Key.
- Real-world examples: Your Hong Kong ID number, your Student ID number, or a book's ISBN number.
- Why it matters: It prevents confusion and ensures that we are updating or deleting the correct information.
Quick Review: Which of these would make a good Primary Key?
1. Home Address (No, brothers/sisters live at the same place!)
2. Student ID Number (Yes! It is unique to you.)
3. Database Features: What can we do?
Once we have our data in a database file, we can process it in many ways. Remember our "Information Processing" rule: Input -> Process -> Output.
A. Basic Operations
- Saving and Retrieving: Keeping the database file safe on a storage device and opening it again later.
- Adding and Deleting: Putting in a new student's info or removing someone who has left the school.
- Editing: Changing information, like updating a student's new home address.
B. Organizing Data
- Sorting: Putting records in a specific order. This could be Alphabetical (A to Z) or Numerical (1 to 100).
- Searching: Finding a specific record quickly, like looking up a book title in the library system.
C. Queries (Asking Questions)
A Query is a way of asking the database a specific question to filter data. Instead of looking at 1,000 students, you can use a query to "List only the students who are in the Basketball Team."
We often use Relational Operators in queries, such as:
- \( = \) (Equal to)
- \( > \) (Greater than)
- \( < \) (Less than)
- \( >= \) (Greater than or equal to)
- \( <= \) (Less than or equal to)
- \( <> \) (Not equal to)
4. Presenting the Information
After we process the data, we need to show it to people in a way that is easy to read. Database software provides three main tools for this:
- Forms: These look like paper forms on the screen. They make it easy to enter or view one record at a time.
- Reports: These are designed to be printed. They summarize the data (e.g., "A list of all students who passed the ICT test").
- Labels: These are small, formatted outputs used for printing things like mailing addresses onto stickers.
5. Databases and Artificial Intelligence (AI)
Did you know? Data is one of the three key elements that make AI work (the others are Algorithms and Computing Power). AI systems need to "learn" from massive databases of information. If the data in the database is biased or wrong, the AI will also make biased or wrong decisions! This is why we say "Garbage In, Garbage Out" (GIGO).
Key Takeaway: Databases are essential tools for Information Processing. They help us turn raw data into useful, organized information through searching, sorting, and querying.
Quick Summary Checklist:
- Can I define Field, Record, and File?
- Do I know why a Primary Key must be unique?
- Can I explain the difference between a Form and a Report?
- Do I understand how a Query helps us find specific information?