- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I alter table column datatype on more than 1 column at a time in MySql?
To add more than 1 column with ALTER table command, you can use MODIFY column command. The syntax is as follows −
alter table yourTableName modify column yourColumnName1 dataType, modify column yourColumnName2 dataType, . . . modify column yourColumnNameN dataType
To understand the above syntax, let us create a table. The following is the query −
mysql> create table AddColumn −> ( −> StudentID int, −> StudentName varchar(200) −> ); Query OK, 0 rows affected (0.49 sec)
Above we have two columns in the table “AddColumn”. In this we will see how to modify more than one column datatype −
mysql> alter table AddColumn −> modify column StudentName varchar(300), −> modify column StudentId varchar(50); Query OK, 0 rows affected (1.95 sec) Records: 0 Duplicates: 0 Warnings: 0
Check whether the modified column added successfully in the table or not. The query is as follows −
mysql> desc AddColumn;
The following is the output −
+-------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+-------+ | StudentId | varchar(50) | YES | | NULL | | | StudentName | varchar(300) | YES | | NULL | | +-------------+--------------+------+-----+---------+-------+ 2 rows in set (0.00 sec)
Now look at the sample output, both column have been changed.
- Related Articles
- How do I alter a MySQL table column defaults?
- How to sort more than one column at a time in MySQL?
- Alter a table column from VARCHAR to NULL in MySQL
- How do I add more members to my ENUM - type column in MySQL?
- How do I update the decimal column to allow more digits in MySQL?
- How do I see what character set a MySQL database / table / column is?
- How to use ALTER TABLE statement for changing the size of a column in MySQL?
- Alter a MySQL column to be AUTO_INCREMENT?
- How to add column using alter in MySQL?\n
- Match column I with column II. There can be more than one match.
- How can I remove every column in a table in MySQL?
- How do I select data from one table only where column values from that table match the column values of another table in MySQL?
- How do I remove ON UPDATE CURRENT_TIMESTAMP from an existing column in MySQL?
- MySQL query to include more than one column in a table that doesn't already exist
- How do I see all foreign keys to a table column?

Advertisements