Skip to main content
Module 9 · Lesson 3 of 435/57 in the course~14 min
Module lessons (3/4)

Changing Table Structure: ALTER TABLE

Lesson preview5 hands-on exercises readySQL Course · Module 9 — Data Structures and DDL

Add, alter, and drop columns and constraints safely on existing tables.

What you'll learn in this lesson

  • Add, remove and rename columns safely using ALTER TABLE.
  • Edit types (ALTER COLUMN ... TYPE) and add/remove constraints (ADD CONSTRAINT, SET NOT NULL) on tables already in production.
  • Understand the impact of ALTER TABLE on legacy data and table locks.

Overview

Requirements are constantly changing: new features ask for extra columns, new constraints or clean renames. ALTER TABLE modifies the schema of already populated tables without having to recreate them from scratch — as long as you carefully manage existing data, DEFAULT and locks.

Each change to the schema (ALTER TABLE ADD COLUMN, adding constraints or indexes) interacts with the table's lookup structures. Explore here how PostgreSQL chooses between sequential scan and B-Tree lookup depending on selectivity and the presence of an index:

Sections covered in this lesson

  1. 11. Mental Model: Main Operations on ALTER TABLE
  2. 22. Progressive & Annotated Examples
  3. 33. Interactive Laboratory: How Indexes and Metadata Guide Searches
  4. 44. Diagnostic Verification (Quiz)
  5. 55. Progressive Practical Laboratory
Pro Lesson · Module 9 — Data Structures and DDL

Unlock "Changing Table Structure: ALTER TABLE" and the full SQL Course curriculum

Add, alter, and drop columns and constraints safely on existing tables.

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.