The ALTER TABLE statement is used to add, delete, or modify columns in an existing table. This is what you’ll use when the table structure needs changes after it has already been created.
You can:
- Add new columns
- Rename columns
- Change column data types
- Drop (remove) columns
- Add or remove constraints
Add a New Column
Adds a new column phone to the students table.
ALTER TABLE students
ADD COLUMN phone VARCHAR(15);
Rename a Column
Changes column name to full_name.
ALTER TABLE students
RENAME COLUMN name TO full_name;
Change Data Type
Changes the data type of age from INT to SMALLINT.
ALTER TABLE students
ALTER COLUMN age TYPE SMALLINT;
Drop (Remove) a Column
Removes the email column.
ALTER TABLE students
DROP COLUMN email;
Rename the Table
Renames the whole table to learners.
ALTER TABLE students
RENAME TO learners;