How can we add multiple columns, with single command, to an existing MySQL table?

MySQLMySQLi Database

We can also add multiple columns to an existing table with the help of ALTER command. The syntax for it would be as follows −

Syntax

Alter table table-name ADD (column-name1 datatype, column-name2 datatype,… column-nameN datatype);

Example

In the example below, with the help of ALTER Command, columns ‘Address’, ‘Phone’ and ‘Email’ are added to the table ‘Student’.

mysql> Alter Table Student ADD(Address Varchar(25), Phone INT, Email Varchar(20));
Query OK, 5 rows affected (0.38 sec)
Records: 5 Duplicates: 0 Warnings: 0
raja
Published on 19-Feb-2018 08:25:11
Advertisements