Database

Alter Table Statement in MySQL : How to Add Multiple Columns in Table

add-multiple-column
mm
Written by Santosh Prasad

In this article I will show you how to add multiple columns in table.

ADD MULTIPLE COLUMNS IN TABLE

Syntax

Follow the below syntax to add multiple columns in table.

ALTER TABLE table_name
  ADD new_column_name column_definition
    [ FIRST | AFTER column_name ],
  ADD new_column_name column_definition
    [ FIRST | AFTER column_name ],
  ...
;

Where;

  • table_name : Name of the table to modify.
  • new_column_name : Name of the new column to add to the table.
    column_definition : Data type and definition of the column such as NULL or NOT NULL.
  • FIRST | AFTER column_name : This is optional, it tells where in the table to create the column. If this is not mentioned by default new column will be added to the end of the table.

Example

Let’s see how to add multiple columns in a MySQL table using the Alter Table statement.

ALTER TABLE contacts
  ADD last_name varchar(40) NOT NULL
    AFTER contact_id,
  ADD first_name varchar(35) NULL
    AFTER last_name;

In the above example MySQL Alter Table will add two columns to the contacts table called last_name and first_name.

Thank you! for visiting Look Linux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at Look Linux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.