
- 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 use ALTER TABLE statement for changing the size of a column in MySQL?
It can be understood with the help of the following example using the table named ‘Student’ having the following description −
mysql> DESCRIBE Student; +--------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | Name | varchar(20) | YES | | NULL | | | RollNo | int(11) | YES | | NULL | | | Grade | varchar(10) | YES | | NULL | | +--------+-------------+------+-----+---------+-------+ 3 rows in set (0.06 sec)
The above result set shows that we have declared the size of the ‘Name’ field is 20.
Now suppose we want to increase its size from 20 to 50 then the following query will do it −
mysql> ALTER TABLE Student MODIFY column Name Varchar(50); Query OK, 3 rows affected (0.85 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> DESCRIBE Student; +--------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | Name | varchar(50) | YES | | NULL | | | RollNo | int(11) | YES | | NULL | | | Grade | varchar(10) | YES | | NULL | | +--------+-------------+------+-----+---------+-------+ 3 rows in set (0.06 sec)
From the above result set, we can see that the size of the column ‘Name’ has been changed to 50.
- Related Articles
- How do I alter a MySQL table column defaults?
- Alter a table column from VARCHAR to NULL in MySQL
- How to modify the size of column in MySQL table?
- How can we use MySQL ALTER TABLE command for adding comments on columns?
- How to alter the data type of a MySQL table’s column?
- How to alter the database engine of a MySQL database table?
- How to alter multiple columns in a single statement in MySQL?
- Which statement, other than ALTER TABLE statement, can be used to apply UNIQUE constraint to the field of an existing MySQL table?
- Can we use ADD and CHANGE with ALTER Statement in MySQL?
- How do I alter table column datatype on more than 1 column at a time in MySql?
- Alter a MySQL column to be AUTO_INCREMENT?
- How to add column using alter in MySQL?\n
- How to alter column type of multiple columns in a single MySQL query?
- How can we use MySQL SELECT statement to count number of rows in a table?
- How can I get the information about a particular column of a table by MySQL EXPLAIN statement?\nEXPLAIN statement?

Advertisements