ALTER TABLE – Changing the Structure of a SQL Table

(because sometimes your table needs a little upgrade)

Quick Syntax Time

Wanna add a new column? Change one? Drop it entirely? ALTER TABLE is your tool.

ALTER TABLE table_name
ADD column_name data_type;

ALTER TABLE table_name
DROP COLUMN column_name;

ALTER TABLE table_name
MODIFY column_name new_data_type;

“Hey SQL, I wanna tweak the design of my table — not the data, just the layout.”

Add a New Column – let’s say email

You suddenly realize…
“Bro, how do I not have emails saved?!”

ALTER TABLE friends
ADD email VARCHAR(100);

Output:

Query OK, 1 row affected
idnameagephoneemail
1Olivia265550001234NULL
2Mason245556712345NULL
3Zoe305559083344NULL
4Ethan215554421199NULL
5Harper255552223344NULL

Remove a Column – you don’t want email anymore?

“Ugh… forget it, too much spam anyway.”

ALTER TABLE friends
DROP COLUMN email;

Output:

Query OK, 1 row affected
idnameagephone
1Olivia265550001234
2Mason245556712345
3Zoe305559083344
4Ethan215554421199
5Harper255552223344

Change a Column’s Type – phone needs more space?

Phone numbers getting longer? International maybe? No stress.

ALTER TABLE friends
MODIFY phone VARCHAR(20);

Output:

Query OK, 1 row affected

Now you can store up to 20 characters in the phone column.
Even numbers like +1-555-222-3344 will fit.

Recap – ALTER is your table’s personal stylist

  • ADD – bring in a new column
  • DROP COLUMN – remove the clutter
  • MODIFY – upgrade what’s already there

It’s like renovating your data house — no moving out required.

Now that you know how to change your tables around, if you want to learn more about removing things from your database, you can read more here:
More about removing from your database

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top