我们如何修改MySQL中列数据类型的声明大小?
可以借助MySQL的ALTERTABLE命令来完成。考虑表'Student',其中'Grade'列的大小声明为Varchar(10),可以从以下查询中看到-
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)
现在假设我们想将其大小从VARCHAR(10)增加到VARCHAR(50),那么下面的查询将做到这一点-
mysql> ALTER TABLE Student MODIFY column Grade Varchar(50); Records: 3 Duplicates: 0 Warnings: 0 mysql> DESCRIBE Student; +--------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | Name | varchar(20) | YES | | NULL | | | RollNo | int(11) | YES | | NULL | | | Grade | varchar(50) | YES | | NULL | | +--------+-------------+------+-----+---------+-------+ 3 rows in set (0.06 sec)
从上面的查询中,我们可以看到“Grade”列的大小已更改为VARCHAR(50)。