Lecture 1: Introduction to Database Concepts
Introduction to Relational Databases
This work is licensed under CC BY-NC-SA 4.0
© Way-Up 2025
Commands to define and modify database structure:
Key point: DDL operations affect the schema, not the data itself
Commands to manage data within tables:
Key point: DML operations work with data, not structure
Most of your daily work will be DML queries, especially SELECT
Commands to control access and permissions:
Example scenarios:
Security principle: Give minimum necessary permissions
| Type Name | Description |
|---|---|
| CHAR(n) | Fixed length characters string |
| VARCHAR(n) | Variable length characters string |
| TEXT | Infinite length characters string |
| INT | Integer numeric value |
| FLOAT(n) | Floating point numeric value |
| DATE | Stores the date only |
| TIME | Stores the time only |
| Type Name | Description | Use Case |
|---|---|---|
| TIMESTAMP | Stores date and time | Audit trails, event logging |
| DATETIME | Stores date and time with wider range | Historical dates, future planning |
| JSON | Stores structured documents | Flexible schemas, API responses |
| BLOB | Binary Large Object | Images, files (not recommended) |
Best Practice: Store files on disk/cloud, keep only references (URLs/paths) in database
Databases ensure data integrity through ACID properties:
| Property | Description | Example |
|---|---|---|
| Atomicity | All or nothing | Bank transfer: debit AND credit must both succeed |
| Consistency | Valid state transitions | Constraints are always respected |
| Isolation | Concurrent operations don't interfere | Two users booking the same seat simultaneously |
| Durability | Saved data persists permanently | Data survives system crash |
Example of redundancy problem:
Order1: Customer="John", Address="123 Main St", Product="Laptop" Order2: Customer="John", Address="123 Main St", Product="Mouse" → If John moves, we must update multiple rows!
Solution: Separate Customers table + Orders table
| Normal Form | Requirement | Eliminates |
|---|---|---|
| 1NF | Atomic values, no repeating groups | Multi-valued attributes |
| 2NF | 1NF + No partial dependencies | Dependencies on part of key |
| 3NF | 2NF + No transitive dependencies | Dependencies on non-key attributes |
| BCNF | 3NF + Every determinant is a candidate key | Remaining anomalies |
Most databases aim for 3NF as a practical balance
| Type | Description | Example | Implementation |
|---|---|---|---|
| One-to-One | One record matches exactly one | Person ↔ Passport | FK in either table |
| One-to-Many | One record matches many | Customer → Orders | FK in "many" table |
| Many-to-Many | Many records match many | Students ↔ Courses | Junction table needed |
Wrong data types can lead to performance issues and data loss!
Next lecture: Entity-Relationship modeling and practical database design!
To practice with MySQL, we'll use the ZIP distribution (no installer required)
C:\mysql or ~/mysql)This method gives you full control and is perfect for learning!
After extracting MySQL, initialize the data directory (first time only)
# Navigate to MySQL bin directory
cd C:\mysql\bin # Windows
cd ~/mysql/bin # macOS/Linux
# Initialize MySQL with insecure mode (no root password)
mysqld --initialize-insecure --console
# This creates the data directory and system tables
# Look for: [Server] /usr/local/mysql/bin/mysqld: ready for connections
--initialize-insecure creates root user with NO password (easier for learning)
Start MySQL server from command line
# Start MySQL server (run in one terminal)
mysqld --console
# You should see:
# [Server] X Plugin ready for connections on port 33060
# [Server] MySQL Server ready for connections on port 3306
# Leave this terminal running - this is your MySQL server!
Keep the server terminal open. To stop: Press Ctrl+C
Open a new terminal and connect to MySQL
# Connect as root (no password needed with --initialize-insecure)
mysql -u root
# You should see:
# Welcome to the MySQL monitor.
# mysql>
# Try your first command:
mysql> SHOW DATABASES;
mysql> CREATE DATABASE test_db;
mysql> USE test_db;
mysql> CREATE TABLE hello (id INT, message VARCHAR(50));
mysql> INSERT INTO hello VALUES (1, 'Hello MySQL!');
mysql> SELECT * FROM hello;
For a better experience, use DBeaver - a free, universal database client
Why DBeaver?

Select MySQL (not PostgreSQL!)
localhost3306 (default MySQL port)test_dbrootClick "Test Connection" to verify. DBeaver may download MySQL drivers automatically.
SHOW DATABASES;
CREATE DATABASE my_first_db;
USE my_first_db;
CREATE TABLE students (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100),
age INT
);
INSERT INTO students (name, age) VALUES ('Alice', 20);
SELECT * FROM students;
Ctrl+Enter (Windows/Linux) or Cmd+Enter (macOS) to executeYou now have two ways to work with MySQL:
| Method | When to Use | Pros |
|---|---|---|
Command Linemysql -u root |
Quick queries, scripts | Fast, lightweight, scriptable |
| DBeaver | Exploration, complex queries | Visual, autocomplete, ER diagrams |
Next step: Complete the homework exercises using either tool!