如何在单个MySQL查询中更改多个列的列类型?
要更改单个MySQL查询中多个列的列类型,语法如下-
alter table yourTableNamemodify column yourColumnName 1 yourDataType1,
modify column yourColumnName 2 yourDataType2,
.
.
N;
让我们首先创建一个表-
create table DemoTable(
Id varchar(100),
FirstName text,
LastName text
);
让我们检查表的描述-
desc DemoTable;
这将产生以下输出-
+-----------+--------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| Id | varchar(100) | YES | | NULL | |
| FirstName | text | YES | | NULL | |
| LastName | text | YES | | NULL | |
+-----------+--------------+------+-----+---------+-------+
3 rows in set (0.09 sec)
以下是更改多个列的列类型的查询。在这里,我们更改了Id,FirstName和LastName列的列类型-
alter table DemoTablemodify column Id int,
modify column FirstName varchar(50),
modify column LastName varchar(50);
Records: 0 Duplicates: 0 Warnings: 0
让我们再次检查表的描述-
desc DemoTable;
这将产生以下输出-
+-----------+-------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| Id | int(11) | YES | | NULL | |
| FirstName | varchar(50) | YES | | NULL | |
| LastName | varchar(50) | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
以上是 如何在单个MySQL查询中更改多个列的列类型? 的全部内容, 来源链接: utcz.com/z/343638.html