SQL Alter Table

The ALTER TABLE command allows you to make changes to an existing table’s structure without deleting or recreating it. This includes adding, removing, renaming, or changing columns.

Tutorials dojo strip

SQL Alter Table Syntax

ALTER TABLE table_name
action;

SQL Alter Table Example

CREATE TABLE employees (
    emp_id INT PRIMARY KEY,
    full_name VARCHAR(100),
    department VARCHAR(50)
);

SQL Alter Table Add Column Example

This command adds a new column to an existing table.

ALTER TABLE employees
ADD birthdate DATE;

SQL Alter Table Drop Column Example

This command removes a column from the table.

ALTER TABLE employees
DROP COLUMN department;

SQL Alter Table Rename Column Example

This command renames an existing column.

ALTER TABLE employees
RENAME COLUMN full_name TO name;

SQL Alter Table Modify Datatype Example

This command changes the data type of a column (for MySQL-compatible syntax).

ALTER TABLE employees
MODIFY name VARCHAR(150);

SQL Alter Table Change Data Type Example

This command changes a column’s data type using ALTER COLUMN (commonly used in PostgreSQL or SQL Server)

ALTER TABLE employees
ALTER COLUMN name TYPE TEXT;

SQL Alter Table Labs

Tutorials dojo strip
Scroll to Top