让我们首先创建一个表。在这里,我们有两列的varchar类型-
mysql> create table DemoTable ( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserFirstName varchar(10), UserLastName varchar(20) , UserAge int );
让我们使用DESC命令检查表的描述-
mysql> desc DemoTable;
这将产生以下输出-
+---------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------+------+-----+---------+----------------+ | UserId | int(11) | NO | PRI | NULL | auto_increment | | UserFirstName | varchar(10) | YES | | NULL | | | UserLastName | varchar(20) | YES | | NULL | | | UserAge | int(11) | YES | | NULL | | +---------------+-------------+------+-----+---------+----------------+ 4 rows in set (0.00 sec)
以下是在MySQL中更新varchar类型的列以增加其长度的查询-
mysql> alter table DemoTable modify UserFirstName varchar(40); Records: 0 Duplicates: 0 Warnings: 0
让我们再次检查表的描述以检查我们在上面所做的事情。我们更新了varchar类型的长度-
mysql> desc DemoTable;
这将产生以下输出-
+---------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------+------+-----+---------+----------------+ | UserId | int(11) | NO | PRI | NULL | auto_increment | | UserFirstName | varchar(40) | YES | | NULL | | | UserLastName | varchar(20) | YES | | NULL | | | UserAge | int(11) | YES | | NULL | | +---------------+-------------+------+-----+---------+----------------+ 4 rows in set (0.00 sec)