Introduction to Relational Databases
The Spreadsheet Analogy
To understand a Relational Database, start with something familiar: a spreadsheet. Most modern apps use databases to store and retrieve data efficiently.
Welcome to your journey into SQL! To understand how databases work, think of a simple spreadsheet like Excel or Google Sheets. A database is essentially a collection of these spreadsheets, where we refer to each individual sheet as a Table. Exactly. Just like a sheet for 'Movies' or 'Customers', a table holds a specific collection of related data.
- A database is like a collection of spreadsheets.
- Each 'sheet' in a database is called a Table.
- Relational databases are the backbone of apps like Netflix and banking systems.
Rows and Columns
Data in a table is organized into Rows and Columns. This rigid structure ensures consistency across all records.
Every table is a grid of information. A Row, also called a Record, is a single horizontal entry—in our case, one specific movie. A Column, or Field, is a vertical category that describes every movie in that list, such as its title or release year. When you look at a specific cell, you are looking at one piece of data defined by its unique row and column.
- Rows (Records) represent individual entries (e.g., one movie).
- Columns (Fields) represent categories (e.g., Title, Year).
- Every entry in a column must follow the same data type.
Meet the Movie Table
Throughout this course, we will use the Movie table. Understanding its schema—the defined structure—is the first step to writing queries.
This is the schema for our Movie table. Think of it as the blueprint. The ID is a unique number for each film. Title and Genre store text, while Year stores the release date as a number. Note the data types. Numbers and Text are treated differently in SQL, which we will explore as we start querying.
- ID: Unique identifier (Number)
- Title: Name of the film (Text)
- Genre: Category (Text)
- RatingCode: Age rating (Text)
- Year: Release year (Number)
Why Use SQL?
Spreadsheets are fine for small lists, but databases can hold millions of rows. SQL is how we 'talk' to the data without scrolling manually.
Imagine this table had ten million movies instead of ten. Scrolling for a specific Sci-Fi film would take hours! SQL, or Structured Query Language, allows us to ask the database for exactly what we want using specific commands.
- SQL stands for Structured Query Language.
- Commands like SELECT and WHERE filter data instantly.
- SQL is much faster than manual searching in large datasets.
Data Detective
Identify the specific Row and Column for a piece of data.
Let's test your eye for detail. Look at the table and click on the cell that represents the 'Genre' of the movie 'Inception'. Not quite. Remember to find the row for 'Inception' first, then move across to the 'Genre' column. Great job! You found the intersection of the 'Inception' row and the 'Genre' column.
- Locating data within the grid structure.
- Understanding the intersection of records and fields.