借助CHANGE命令增加数据库中现有列的varchar大小。语法如下-
alter table yourTableName change yourColumnName yourColumnName dataType;
在这里,我们正在创建一个单列且varchar大小为200的表-
mysql> create table IncreaseVarcharDemo −> ( −> StudentId varchar(200) −> );
现在在表中插入记录。查询如下-
mysql> insert into IncreaseVarcharDemo values('John123');
在以下查询的帮助下显示表中的所有记录-
mysql> select *from IncreaseVarcharDemo;
以下是输出-
+-----------+ | StudentId | +-----------+ | John123 | +-----------+ 1 row in set (0.00 sec)
以下是将varchar大小从200增加到1000的查询-
mysql> alter table IncreaseVarcharDemo change StudentId StudentId varchar(1000); Records: 0 Duplicates: 0 Warnings: 0
现在您可以检查varchar大小是否已增加。查询如下-
mysql> desc IncreaseVarcharDemo;
以下是输出-
+-----------+---------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+---------------+------+-----+---------+-------+ | StudentId | varchar(1000) | YES | | NULL | | +-----------+---------------+------+-----+---------+-------+ 1 row in set (0.03 sec)