Adding multiple columns in between columns – MySQL

When working with several RDBMSs, even minor changes in syntax can cause difficulties. This is the first in a series of postings about how to add multiple columns to various RDBMSs. This tutorial, on the other hand, will cover MySQL syntax, including not only how to add multiple columns but also how to place them between the required columns.

Syntax:
ALTER TABLE tableName
ADD COLUMN `column1` dataType ColumnPosition,
ADD COLUMN `column2` dataType ColumnPosition,
ADD COLUMN `column3` dataType ColumnPosition;

Example:
ALTER TABLE Customers
ADD COLUMN `CxID` SMALLINT(6) NOT NULL FIRST,
ADD COLUMN `LastName` VARCHAR(20) AFTER ‘FirstName’,
ADD COLUMN `status` INT(10) UNSIGNED NOT NULL AFTER `UpdateTime`;

Hope you find this article helpful.

Please subscribe for more interesting updates.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s