Computer Science
Grade 10
20 min
Relational Databases
Relational Databases
Tutorial Preview
1
Introduction & Learning Objectives
Learning Objectives
Define what a relational database is and its core components.
Identify tables, rows (records), and columns (fields) in a database schema.
Explain the purpose and characteristics of a Primary Key.
Explain how a Foreign Key is used to create relationships between tables.
Describe the difference between one-to-many and many-to-many relationships.
Interpret a simple Entity-Relationship Diagram (ERD).
Write a basic SQL SELECT statement to retrieve data from a single table.
Ever wonder how your favorite game instantly loads your character's level, inventory, and achievements? 🎮 That's the magic of a well-organized database!
In this lesson, you'll learn about relational databases, the most common way to store and manage structured data. We...
2
Key Concepts & Vocabulary
TermDefinitionExample
Table (Relation)A collection of related data organized in a grid format with columns and rows. It represents a single 'entity' or concept.A `Students` table would store information exclusively about students.
Row (Record or Tuple)A single entry or item within a table. It represents one instance of the entity.In a `Students` table, one row would contain all the information for a single student, like '101, Alice, Smith, 10'.
Column (Field or Attribute)A single piece of data that exists for every row in the table. It defines a property of the entity.In a `Students` table, columns could be `StudentID`, `FirstName`, `LastName`, and `GradeLevel`.
Primary Key (PK)A column (or set of columns) that contains a unique value for each row in a table. It cannot...
3
Core Syntax & Patterns
Primary Key Integrity Rule
Every Primary Key value must be UNIQUE and NOT NULL.
This rule ensures that every row in a table can be reliably and uniquely identified. You can't have two students with the same ID, and every student must have an ID.
Referential Integrity Rule (Foreign Keys)
A Foreign Key value must match an existing Primary Key value in the table it references, or it can be NULL.
This rule prevents 'orphan' records. For example, you cannot enroll a `StudentID` of 999 in a course if no student with ID 999 exists in the `Students` table.
Basic SQL SELECT Syntax
SELECT column_name(s) FROM table_name WHERE condition;
This is the fundamental structure for retrieving data. `SELECT` specifies which columns you want, `FROM` specifies which table t...
4 more steps in this tutorial
Sign up free to access the complete tutorial with worked examples and practice.
Sign Up Free to ContinueSample Practice Questions
Challenging
You need to design a simple database for a music collection to track albums and the artists who created them. Assume an artist can have many albums, but each album is by only one artist. Which schema is the most appropriate and normalized design?
A.One table `Music` with columns for both album and artist details.
B.Two tables: `Artists` (PK: `ArtistID`) and `Albums` (PK: `AlbumID`, FK: `ArtistID`).
C.Two tables: `Artists` (PK: `ArtistID`, FK: `AlbumID`) and `Albums` (PK: `AlbumID`).
D.Two tables, `Artists` and `Albums`, with no keys linking them.
Challenging
A classmate writes the SQL query: `SELECT ProductName FROM Products WHERE Category == 'Electronics';`. Based on the tutorial's 'Common Pitfalls', what is the specific error in this statement?
A.The column name `ProductName` should be in quotes.
B.The `SELECT` keyword should be in lowercase.
C.The `WHERE` clause uses a double equals sign (`==`) for comparison, but standard SQL requires a single equals sign (`=`).
D.The semicolon (`;`) at the end is mandatory and is missing.
Challenging
A database uses a member's `EmailAddress` as the Primary Key. A member, 'jane.doe@email.com', is referenced as a Foreign Key in an `EventSignups` table. If Jane updates her email to 'jane.smith@email.com', what critical problem does this cause?
A.It violates the Primary Key's 'NOT NULL' rule because her old email is no longer valid.
B.It breaks referential integrity; the `EventSignups` table now points to an email that no longer exists in the members table.
C.It proves that an email address is not unique, which is a requirement for a Primary Key.
D.It is not a problem, as long as the administrator remembers to update the `EventSignups` table manually.
Want to practice and check your answers?
Sign up to access all questions with instant feedback, explanations, and progress tracking.
Start Practicing Free