
- 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 to alter column type of multiple columns in a single MySQL query?
To alter column type of multiple columns in a single MySQL query, the syntax is as follows −
alter table yourTableName modify column yourColumnName 1 yourDataType1, modify column yourColumnName 2 yourDataType2, . . N;
Let us first create a table −
mysql> create table DemoTable ( Id varchar(100), FirstName text, LastName text ); Query OK, 0 rows affected (0.52 sec)
Let us check the description of table −
mysql> desc DemoTable;
This will produce the following output −
+-----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+--------------+------+-----+---------+-------+ | Id | varchar(100) | YES | | NULL | | | FirstName | text | YES | | NULL | | | LastName | text | YES | | NULL | | +-----------+--------------+------+-----+---------+-------+ 3 rows in set (0.09 sec)
Following is the query to alter column type of multiple columns. Here, we have altered the column type of columns Id, FirstName and LastName −
mysql> alter table DemoTable modify column Id int, modify column FirstName varchar(50), modify column LastName varchar(50); Query OK, 0 rows affected (1.63 sec) Records: 0 Duplicates: 0 Warnings: 0
Let us check the description of table once again −
mysql> desc DemoTable;
This will produce the following output −
+-----------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+-------+ | Id | int(11) | YES | | NULL | | | FirstName | varchar(50) | YES | | NULL | | | LastName | varchar(50) | YES | | NULL | | +-----------+-------------+------+-----+---------+-------+ 3 rows in set (0.00 sec)
- Related Articles
- How to alter multiple columns in a single statement in MySQL?
- Change multiple columns in a single MySQL query?
- MySQL query to sort multiple columns together in a single query
- MySQL query to combine two columns in a single column?
- Select multiple columns and display in a single column in MySQL?
- How to alter the data type of a MySQL table’s column?
- How to sort multiple columns with a single query?\n
- How can we sort multiple columns in a single query?
- Add a new column and index to an existing table with ALTER in a single MySQL query?
- How do I insert multiple values in a column with a single MySQL query?
- A single MySQL query to search multiple words from different column values
- How to get multiple rows in a single MySQL query?
- How to obtain multiple rows in a single MySQL query?
- Get multiple count in a single MySQL query for specific column values
- How to check multiple columns for a single value in MySQL?

Advertisements