SQL Tutorial

Relational Database Basics

Understand tables, rows, columns, primary keys, foreign keys and relationships.

Concept

A relational database stores data in tables. Each row represents a record, columns describe attributes, and keys help identify or connect records.

Good table design avoids repeating the same facts unnecessarily. Primary keys uniquely identify rows, while foreign keys express relationships between tables.

Example

CREATE TABLE students (
  student_id INTEGER PRIMARY KEY,
  name VARCHAR(100) NOT NULL,
  city VARCHAR(80)
);
Type the example yourself and change at least one value. Small experiments reveal syntax and behavior faster than passive reading.

Practice Tasks

  1. Design a courses table with a primary key.
  2. Design an enrollments table that connects students and courses.
  3. Identify which columns should be NOT NULL.

Key Takeaways

  • Tables model entities or relationships.
  • Keys protect identity and relationships.
  • Schema design affects query clarity and data quality.