MySQL ALTER TABLE – Add Multiple Columns

I not too long ago wanted so as to add a number of columns to an current desk to retailer abstract knowledge calculations and questioned if I might do it in a single MySQL ALTER TABLE assertion. Seems you possibly can. And, it’s tremendous easy. Handy too. Proceed studying and study what I realized…

 

The Publication for PHP and MySQL Builders

Obtain a duplicate of my e-book, “10 MySQL Suggestions For Everybody”, completely free whenever you subscribe to the OpenLampTech publication.

MySQL ALTER TABLE

In MySQL, so as to add a brand new column to an current desk, the ALTER TABLE syntax would appear to be this:

ALTER TABLE table_name ADD COLUMN column_name column_definition;

Let’s attempt including a number of columns in a single command.

I’ve this arbitrary desk with 2 columns:

DESC a_tab;

 

We begin with ALTER TABLE table_name ADD COLUMN like regular. Then specify nonetheless many columns we wish, with the required definition for every, enclosed in parentheses.

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

Checking the desk definition once more, we will see the three new columns have been added, all with one ALTER TABLE command:

DESC a_tab;

Viola. Really easy, proper?


Do you must study MySQL? Simply beginning and confused about easy methods to question a desk and get the information you want? I’m creating premium MySQL Newcomers content material for this particular motive. To assist those that need to study the fundamentals of MySQL however don’t know the place to start out. Study extra in regards to the premium weblog posts as I develop and launch them.


Like what you could have learn? See something incorrect? Please remark under and thanks for studying!!!

A Name To Motion!

Thanks for taking the time to learn this submit. I really hope you found one thing fascinating and enlightening. Please share your findings right here, with another person you recognize who would get the identical worth out of it as nicely.

Go to the Portfolio-Projects page to see weblog posts/technical writing I’ve accomplished for purchasers.

To obtain e mail notifications (By no means Spam) from this weblog (“Digital Owl’s Prose”) for the most recent weblog posts as they’re printed, please subscribe (of your personal volition) by clicking the ‘Click on To Subscribe!’ button within the sidebar on the homepage! (Be at liberty at any time to evaluate the Digital Owl’s Prose Privacy Policy Page for any questions you could have about: e mail updates, opt-in, opt-out, contact varieties, and many others…)

Be certain and go to the “Best Of” web page for a group of my greatest weblog posts.


Josh Otwell has a ardour to check and develop as a SQL Developer and blogger. Different favourite actions discover him along with his nostril buried in e-book, article, or the Linux command line. Amongst these, he shares a love of tabletop RPG video games, studying fantasy novels, and spending time along with his spouse and two daughters.

Disclaimer: The examples introduced on this submit are hypothetical concepts of easy methods to obtain related varieties of outcomes. They aren’t the utmost greatest resolution(s). The bulk, if not all, of the examples supplied, are carried out on a private growth/studying workstation setting and shouldn’t be thought of manufacturing high quality or prepared. Your explicit objectives and wishes might differ. Use these practices that greatest profit your wants and objectives. Opinions are my very own.


Take a look at this text from the OpenLampTech publication web page, Book Recommendation – SQL Antipatterns.


How can I allow you to?

Disclosure: A number of the providers and merchandise hyperlinks on this submit are affiliate hyperlinks. At no extra value to you, must you make a purchase order by clicking via considered one of them, I’ll obtain a fee.

Disclosure: A number of the providers and merchandise hyperlinks on this submit are affiliate hyperlinks. At no extra value to you, must you make a purchase order by clicking via considered one of them, I’ll obtain a fee.


Assist my content material with a Tip. Thanks a lot!!!


The Publication for PHP and MySQL Builders

Obtain a duplicate of my e-book, “10 MySQL Suggestions For Everybody”, completely free whenever you subscribe to the OpenLampTech publication.

Leave a Reply

Your email address will not be published.