您可以为此使用Modify命令。让我们首先创建一个表。
mysql> create table DemoTable ( StudentId varchar(200) not null, StudentName varchar(20), StudentAge int, StudentAddress varchar(20), StudentCountryName varchar(20) );
现在检查表的描述。
mysql> desc DemoTable;
这将产生以下输出-
+--------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------------+--------------+------+-----+---------+-------+ | StudentId | varchar(200) | NO | | NULL | | | StudentName | varchar(20) | YES | | NULL | | | StudentAge | int(11) | YES | | NULL | | | StudentAddress | varchar(20) | YES | | NULL | | | StudentCountryName | varchar(20) | YES | | NULL | | +--------------------+--------------+------+-----+---------+-------+ 5 rows in set (0.00 sec)
这是将数据类型从varchar更改为BIGINT的查询-
mysql> alter table DemoTable modify StudentId BIGINT(10) UNSIGNED NOT NULL DEFAULT 0; Records: 0 Duplicates : 0 Warnings : 0
上面,我们已将“ StudentId”列的数据类型从varchar(200)更改为BIGINT(10)。让我们再次检查表的描述。
mysql> desc DemoTable;
这将产生以下输出-
+--------------------+---------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------------+---------------------+------+-----+---------+-------+ | StudentId | bigint(10) unsigned | NO | | 0 | | | StudentName | varchar(20) | YES | | NULL | | | StudentAge | int(11) | YES | | NULL | | | StudentAddress | varchar(20) | YES | | NULL | | | StudentCountryName | varchar(20) | YES | | NULL | | +--------------------+---------------------+------+-----+---------+-------+ 5 rows in set (0.00 sec)