CodingNic

Altering Tables

Module Overview

Altering Tables 5 min read

Module Overview

What You’ll Learn

  • Modify existing tables
  • Add and remove columns
  • Modify constraints
  • Update table structures safely

💡 Why this module matters: Real tables change after they’re created, a new feature needs a new column, an old constraint needs updating. ALTER TABLE is how a table evolves without losing the data already sitting inside it.

What’s Covered

  • ALTER TABLE, the statement behind every change in this module.
  • Rename tables and rename columns, without touching the data inside.
  • Add columns and drop columns, growing or trimming a table’s structure.
  • Change data types, adjusting a column after the fact.
  • SET/DROP DEFAULT and SET/DROP NOT NULL, adjusting existing constraints.
  • Add/Drop UNIQUE, CHECK, PRIMARY KEY, and FOREIGN KEY, changing what a table enforces.
  • Constraint naming, how PostgreSQL names constraints, and how to name them yourself.

Hands-On

By the end of this module, you’ll modify existing tables, add new columns, change column types, and add and remove constraints, safely, without losing existing data.

Next module shifts from structure back to data, but with a sharper focus: precisely filtering, sorting, and limiting exactly which rows a query returns.