Home > Database > Mysql Tutorial > How to change the size of a column in MySQL using ALTER TABLE statement?

How to change the size of a column in MySQL using ALTER TABLE statement?

WBOY
Release: 2023-09-04 13:37:09
forward
884 people have browsed it

如何使用 ALTER TABLE 语句更改 MySQL 中列的大小?

This can be understood with the help of the following example, using a table named "Student" which is described as follows -

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)
Copy after login

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)
Copy after login

From the above result set, we can see the "Name" column The size has been changed to 50.

The above is the detailed content of How to change the size of a column in MySQL using ALTER TABLE statement?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template