Class 10 of 58 • Database & Table Management (DDL)

SQL ALTER TABLE: Add, Modify, Drop Columns & Schema Evolution

In production software systems, requirements evolve continuously. You frequently need to add phone numbers, expand character limits, rename columns, or attach new foreign keys to existing tables without destroying existing customer data. The ALTER TABLE DDL statement enables safe schema evolution and migrations.


1. Adding New Columns (ADD COLUMN)

To add one or more new columns to an existing table:

-- Add a single phone_number column
ALTER TABLE students
ADD COLUMN phone_number VARCHAR(15) AFTER email;

-- Add multiple columns in a single statement
ALTER TABLE students
ADD COLUMN emergency_contact VARCHAR(100),
ADD COLUMN is_active BOOLEAN DEFAULT TRUE;
Positioning Tip: MySQL allows using FIRST or AFTER column_name to control the physical placement of new columns in the table structure.

2. Modifying Column Types & Constraints (MODIFY / ALTER)

When you need to expand field capacity (e.g., increasing an email field from 50 to 120 characters) or change default values:

-- MySQL Syntax: Expand email column size and enforce NOT NULL
ALTER TABLE students
MODIFY COLUMN email VARCHAR(120) NOT NULL;

-- PostgreSQL Syntax: Alter column data type
ALTER TABLE students
ALTER COLUMN email TYPE VARCHAR(120);

3. Renaming Columns & Tables (RENAME)

Standard ANSI SQL supports renaming columns without data migration scripts:

-- Rename column from 'gpa' to 'grade_point_average'
ALTER TABLE students
RENAME COLUMN gpa TO grade_point_average;

-- Rename the entire table
ALTER TABLE students
RENAME TO university_students;

4. Dropping Columns (DROP COLUMN)

To remove an obsolete column and free physical disk space:

-- Permanently remove emergency_contact column
ALTER TABLE students
DROP COLUMN emergency_contact;

5. Adding & Dropping Table Constraints

You can attach constraints (like primary keys, foreign keys, or unique rules) to tables after creation:

-- Add a named UNIQUE constraint to phone_number
ALTER TABLE students
ADD CONSTRAINT unique_phone UNIQUE (phone_number);

-- Drop the constraint later if business rules change
ALTER TABLE students
DROP INDEX unique_phone; -- MySQL
-- ALTER TABLE students DROP CONSTRAINT unique_phone; -- PostgreSQL/Oracle

Next, let us understand the critical differences between DROP vs TRUNCATE vs DELETE!


Frequently Asked Questions (FAQ)

Yes, provided existing data can be implicitly cast to the new type (e.g., expanding VARCHAR(50) to VARCHAR(100)). If existing text cannot convert to an integer, the database engine will abort the ALTER TABLE with a type conversion error.

MODIFY COLUMN changes the data type or constraints of an existing column without changing its name. CHANGE COLUMN allows you to rename the column AND change its data type simultaneously.

Yes! Dropping a column permanently erases all values stored in that column across all rows in the table.

Next Step in Your SQL Database Learning Path:

Proceed to the next class in sequence to build production mastery of relational database architecture.

Continue to Class 11: DROP vs TRUNCATE vs DELETE → Previous: ← CREATE TABLE | Full Syllabus


Related SQL Masterclass Lessons & Recommended Next Topics

Create Table DDL →

Initial table creation principles and column definitions.

Drop vs Truncate →

Difference between altering, truncating, and dropping tables.

Adding Database Indexes →

Using ALTER TABLE to add B-tree indexes for fast queries.

Table Partitioning →

Altering large tables to implement range and hash partitions.

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Reddit

You may also like this!