MySQL ALTER TABLE – Add Multiple Columns

I recently needed to add multiple columns to an existing table to store summary data calculations and wondered if I could do it in one MySQL ALTER TABLE statement. Turns out you can. And, it’s super simple. Convenient too. Continue reading and learn what I learned…

Image by Gerd Altmann from Pixabay 
The Newsletter for PHP and MySQL Developers

Receive a copy of my ebook, “10 MySQL Tips For Everyone”, absolutely free when you subscribe to the OpenLampTech newsletter.

MySQL ALTER TABLE

In MySQL, to add a new column to an existing table, the ALTER TABLE syntax would look like this:

ALTER TABLE table_name ADD COLUMN column_name column_definition;

Let’s try adding multiple columns in one command.

I have this arbitrary table with 2 columns:

DESC a_tab;

☕☕☕

If you found value in this post, you can show your appreciation and buy me a coffee. It is my favorite drink!

☕☕☕


We start with ALTER TABLE table_name ADD COLUMN like normal. Then specify however many columns we want, with the required definition for each, enclosed in parentheses.

ALTER TABLE a_tab
ADD COLUMN (
name_col VARCHAR(30) DEFAULT 'not sure',
age_col INTEGER DEFAULT NULL,
another_col TEXT
);

Checking the table definition again, we can see the 3 new columns have been added, all with one ALTER TABLE command:

DESC a_tab;

Viola. So easy, right?


Discover premium articles, in-depth guides, instructional videos, and much more by joining the “MySQL Learning Tier” membership. You have access to exclusive content unpublished anywhere else with this membership. With new content being added regularly, continue learning MySQL at any level.


Like what you have read? See anything incorrect? Please comment below and thank you for reading!!!

A Call To Action!

Thank you for taking the time to read this post. I truly hope you discovered something interesting and enlightening. Please share your findings here, with someone else you know who would get the same value out of it as well.

Visit the Portfolio-Projects page to see blog posts/technical writing I have completed for clients.



To receive email notifications (Never Spam) from this blog (“Digital Owl’s Prose”) for the latest blog posts as they are published, please subscribe (of your own volition) by clicking the ‘Click To Subscribe!’ button in the sidebar on the homepage! (Feel free at any time to review the Digital Owl’s Prose Privacy Policy Page for any questions you may have about: email updates, opt-in, opt-out, contact forms, etc…)

Be sure and visit the “Best Of” page for a collection of my best blog posts.


Josh Otwell has a passion to study and grow as a SQL Developer and blogger. Other favorite activities find him with his nose buried in a good book, article, or the Linux command line. Among those, he shares a love of tabletop RPG games, reading fantasy novels, and spending time with his wife and two daughters.

Disclaimer: The examples presented in this post are hypothetical ideas of how to achieve similar types of results. They are not the utmost best solution(s). The majority, if not all, of the examples provided, are performed on a personal development/learning workstation environment and should not be considered production quality or ready. Your particular goals and needs may vary. Use those practices that best benefit your needs and goals. Opinions are my own.


Check out this article from the OpenLampTech publication page, Book Recommendation – SQL Antipatterns.


How can I help you?

Disclosure: Some of the services and product links in this post are affiliate links. At no additional cost to you, should you make a purchase by clicking through one of them, I will receive a commission.

The Newsletter for PHP and MySQL Developers

Receive a copy of my ebook, “10 MySQL Tips For Everyone”, absolutely free when you subscribe to the OpenLampTech newsletter.

Disclosure: Some of the services and product links in this post are affiliate links. At no additional cost to you, should you make a purchase by clicking through one of them, I will receive a commission.


Support my content with a Tip. Thank you so much!!!


The Newsletter for PHP and MySQL Developers

Receive a copy of my ebook, “10 MySQL Tips For Everyone”, absolutely free when you subscribe to the OpenLampTech newsletter.

Hey thanks for commenting! Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.