Skip to main content
Module 8 · Lesson 3 of 431/57 in the course~15 min
Module lessons (3/4)

Creating Tables and Constraints: DDL

Lesson preview5 hands-on exercises readySQL Course · Module 8 — Writing and Modifying Data

CREATE TABLE with PRIMARY KEY, NOT NULL, UNIQUE, FOREIGN KEY, CHECK, and DEFAULT.

What you'll learn in this lesson

  • Define new tables via CREATE TABLE choosing the correct types (SERIAL, INTEGER, NUMERIC, TEXT, BOOLEAN, DATE, TIMESTAMPTZ).
  • Apply essential integrity constraints: PRIMARY KEY, NOT NULL, UNIQUE, REFERENCES (FOREIGN KEY), CHECK, and DEFAULT.
  • Evolve or remove existing tables with ALTER TABLE and DROP TABLE IF EXISTS.

Overview

DDL (Data Definition Language) collects commands that shape the very structure of the database: create tables, impose rules that prevent dirty data from entering and evolve the schema over time with ALTER TABLE.

When you declare REFERENCES customers(id), you enforce the same PK ↔ FK connection at the database engine level that you then query via JOIN: each child row must point to a real parent, otherwise the database rejects the write!

Sections covered in this lesson

  1. 11. Mental Model: Fundamental Types and Integrity Constraints
  2. 22. Progressive & Annotated Examples
  3. 33. Interactive Laboratory: Referential Integrity between Tables
  4. 44. Diagnostic Verification (Quiz)
  5. 55. Progressive Practical Laboratory
Pro Lesson · Module 8 — Writing and Modifying Data

Unlock "Creating Tables and Constraints: DDL" and the full SQL Course curriculum

CREATE TABLE with PRIMARY KEY, NOT NULL, UNIQUE, FOREIGN KEY, CHECK, and DEFAULT.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in SQL Course plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.