
- 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 I modify an existing MySQL column’s data type?
ALTER COMMAND is used to modify an existing MySQL column’s data type. Following is an example which demonstrates that how we can use this command to modify column’s data type −
mysql> describe testing\G *************************** 1. row *************************** Field: id1 Type: int(11) Null: NO Key: PRI Default: 0 Extra: *************************** 2. row *************************** Field: name Type: char(30) Null: YES Key: Default: NULL Extra: 2 rows in set (0.05 sec)
From above DESCRIBE query, we can see that the data type of Name column in CHAR(30). Now with the help of the following query, we can change it to VARCHAR(20) −
mysql> ALTER TABLE Testing MODIFY Name Varchar(20); Query OK, 4 rows affected (0.60 sec) Records: 4 Duplicates: 0 Warnings: 0 mysql> Describe Testing\G; *************************** 1. row *************************** Field: id1 Type: int(11) Null: NO Key: PRI Default: 0 Extra: *************************** 2. row *************************** Field: Name Type: varchar(20) Null: YES Key: Default: NULL Extra: 2 rows in set (0.15 sec)
Now the data type has been modified to VARCHAR(20).
- Related Articles
- How can I modify an existing column's data type?
- How can we modify an existing MySQL event?
- How can we modify column/s of MySQL table?
- How can I drop an existing column from a MySQL table?
- How can I change the name of an existing column from a MySQL table?
- How can we modify an existing module in Java 9?
- What can another keyword be used instead of MODIFY to modify the column/s of MySQL table?
- How can we copy data with some condition/s from existing MySQL table?
- How do I modify a MySQL column to allow NULL?
- How can I move an existing MySQL event to another database?
- How do I remove ON UPDATE CURRENT_TIMESTAMP from an existing column in MySQL?
- How to increase varchar size of an existing column in a database without breaking existing data in MySQL?
- How can I insert default value in MySQL ENUM data type?
- How can I see the CREATE TABLE statement of an existing MySQL table?
- How can we change the data type of the column in MySQL table?

Advertisements