Covers the core components of relational databases including tables, records, fields, and primary keys.
Imagine a library where every book's title, author, and borrower are written on a single, massive scroll. If one person borrows ten books, their name is written ten times. How do we stop this 'data bloat' before the system collapses under its own weight?
A Relational Database organizes information into Tables (formally called relations). Think of a table as a grid. Each vertical column is a Field (or attribute), representing a specific category of data. Each horizontal row is a Record (or tuple), representing one unique instance of the object. Crucially, every field has a Domain: the set of allowable values. For example, if a field is 'QuantityInStock,' its domain might be restricted to non-negative integers . This structure ensures that data remains predictable and searchable.
Quick Check
If a database table stores information about 'Smartphones,' what would a single 'Record' represent?
Answer
A single record would represent one specific smartphone unit or model entry.
In a database with millions of entries, how do we find exactly one specific record? We use a Primary Key (PK). A Primary Key is a field (or a combination of fields) that uniquely identifies every record in a table. A valid PK must follow two strict rules: 1. It must be Unique (no two records can have the same PK). 2. It must be Non-Null (it cannot be empty). While a person's name isn't a good PK (many people share names), a Government ID or a generated Serial Number works perfectly.
Scenario: You are designing a table for a 'High School Student' database. 1. Candidate 1: First Name. Rejected. Multiple students are named 'Alex'. 2. Candidate 2: Date of Birth. Rejected. Multiple students can be born on the same day. 3. Candidate 3: Student ID Number. Accepted. This is unique to every student and never changes.
Quick Check
Why is a 'Phone Number' often a poor choice for a Primary Key in a long-term customer database?
Answer
Phone numbers can change over time or be reassigned to different people, violating the stability required for a primary key.
The 'Relational' in Relational Database refers to how tables connect. Instead of storing a customer's address every time they buy a product (which creates Data Redundancy), we store the address once in a 'Customers' table. We then use the Customer's PK in the 'Orders' table. This process of reducing repetition is called Normalization. By eliminating redundancy, we prevent 'Update Anomalies.' If a customer moves, we update their address in one place, and it is automatically correct for every order they have ever placed.
In a 'Course Enrollment' table, a StudentID isn't unique (a student takes many courses) and a CourseID isn't unique (a course has many students). 1. We create a Composite Key by combining both: . 2. This pair is unique because a specific student can only be enrolled in a specific course once at a time. 3. This allows us to link the 'Students' table and 'Courses' table without repeating student names or course descriptions.
Which term describes the set of all possible valid values for a specific field?
If a table has a Primary Key , which of the following must be true for any two records and ?
Data redundancy is beneficial because it provides backups of information within the same table.
Review Tomorrow
In 24 hours, try to explain to a peer the difference between a Record and a Field, and why a Primary Key cannot be 'Null'.
Practice Activity
Look at a receipt from a recent purchase. Identify which pieces of data (Store Name, Date, Item Price, Credit Card Number) should be in separate tables to reduce redundancy.