SQL ALTER TABLE

Add, rename or remove columns.

✍️ 3 exercises + code challenge in this lesson

ALTER TABLE changes the structure of an existing table:

  • Add a column: ALTER TABLE Customers ADD Phone VARCHAR(20);
  • Rename a column: ALTER TABLE Customers RENAME COLUMN Phone TO Mobile;
  • Remove a column: ALTER TABLE Customers DROP COLUMN Mobile;
  • Rename the table: ALTER TABLE Customers RENAME TO Clients;
  • Change a type: ALTER TABLE ... MODIFY COLUMN (MySQL) or ALTER COLUMN (SQL Server, PostgreSQL).

Key Takeaways: SQL ALTER TABLE

Mastering SQL ALTER TABLE helps you write clean and reliable SQL code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

SQL ALTER TABLE Code Example

SQL
ALTER TABLE Customers ADD Phone VARCHAR(20);
UPDATE Customers SET Phone = '0300-1112223' WHERE CustomerID = 1;
ALTER TABLE Customers RENAME COLUMN Phone TO Mobile;

SELECT CustomerID, CustomerName, Mobile FROM Customers LIMIT 3;
Free sign-in required · Google login available

SQL ALTER TABLE Practice Exercises

Check what you learned in “SQL ALTER TABLE”.

/ 3 solved
Fill in the blank

Add a column to a table.

 Customers ADD Phone TEXT;
✓ Correct! Not quite. Try again.
Multiple choice

Which ALTER TABLE action renames a column?

✓ Correct! Not quite. Try again.
Code challenge

Add a column Discount INTEGER to Products, set it to 10 for ProductID 1, then select ProductName, Discount for ProductID 1.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services