ALTER TABLE … ADD COLUMN lets you extend an existing SQL table by appending new columns without recreating or losing data.
The SQL ALTER TABLE … ADD COLUMN command lets you extend an existing table’s schema without recreating the table, preserving data while adding new attributes.
ALTER TABLE … ADD COLUMN adds a new column definition to an existing table. The table keeps all current rows; the new column is filled with NULL or a supplied default value for each row.
Supply both a DEFAULT expression and the NOT NULL constraint: ALTER TABLE orders ADD COLUMN shipped_at TIMESTAMP NOT NULL DEFAULT NOW();
Databases backfill existing rows with the default so the NOT NULL rule holds instantly.
Standard syntax is ALTER TABLE table_name ADD [COLUMN] column_name data_type [constraints];
Vendors differ mainly on optional keywords and constraint order.
Yes. Separate ADD clauses with commas: ALTER TABLE users ADD COLUMN bio TEXT, ADD COLUMN last_login TIMESTAMP;
One statement is faster than two because the table is rewritten once.
Galaxy autocompletes table names, types, and constraints while you type ALTER TABLE statements. The AI copilot flags missing defaults on NOT NULL columns, preventing costly table rewrites in production.
Teams add columns to store new feature flags, audit data, or analytics fields. In event-driven systems, ADD COLUMN enables gradual schema evolution with zero data loss.
Add IF NOT EXISTS for idempotent migrations: ALTER TABLE metrics ADD COLUMN IF NOT EXISTS source VARCHAR(50);
Repeatable scripts then run safely in CI/CD pipelines.
Locking is engine-specific. PostgreSQL rewrites only when a non-immutable default exists. MySQL adds metadata locks; use ONLINE
keyword in 8.0+ to avoid long blocking.
Specify explicit defaults, test in staging, wrap changes in versioned migrations, and monitor replication lag. Share endorsed migration scripts in Galaxy Collections for team reuse.
This migration adds a JSONB preferences
column, seeds it, and queries it.
-- migration
ALTER TABLE users
ADD COLUMN preferences JSONB NOT NULL DEFAULT '{}'::JSONB;
-- verify existing data
SELECT id, preferences->'theme' AS theme
FROM users;
Adding columns is the most common schema change. Doing it incorrectly can rewrite terabytes, block traffic, or break applications. Understanding vendor-specific behavior lets teams ship features faster while keeping databases online. For analytics pipelines, fast ADD COLUMN maintains data freshness and prevents costly reprocesses.
For most engines, adding a NULLABLE column is instant. A NOT NULL column with a volatile default may lock or rewrite the table. Schedule during low traffic or use online DDL options.
No. Schema changes must run on the primary. Replicas replicate the DDL afterward.
Use ALTER TABLE … DROP COLUMN
. Be sure the column isn’t referenced in queries, indexes, or constraints, and verify application code first.
Galaxy’s AI copilot autowrites ALTER TABLE statements, validates syntax for your connected engine, and lets teams endorse the migration script so everyone reuses the same trusted SQL.