- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can we add multiple columns, with single command, to an existing MySQL table?
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
- Related Articles
- How can we add columns with default values to an existing MySQL table?
- How can we set PRIMARY KEY on multiple columns of an existing MySQL table?
- How to add columns to an existing MySQL table?
- How can we remove composite PRIMARY KEY constraint applied on multiple columns of an existing MySQL table?
- How can we get a list of columns in an existing MySQL table?
- How can we alter table to add MySQL virtual GENERATED COLUMNS?
- How can we alter table to add MySQL stored GENERATED COLUMNS?
- How can we have multiple virtuals GENERATED COLUMNS in MySQL table with CREATE TABLE statement?
- How can we add a FOREIGN KEY constraint to the field of an existing MySQL table?
- How can we update columns values on multiple rows with a single MySQL UPDATE statement?
- How can we get more details about columns of an existing table than return by MySQL SHOW COLUMNS statement?
- How to add columns at specific position in existing table in MySQL?
- How can we use MySQL ALTER TABLE command for adding comments on columns?
- How to add current date to an existing MySQL table?
- How can we add values into the columns of a MySQL table?
Advertisements