
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Change Column Size Using ALTER TABLE 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.
Advertisements