如何在MySQL表中更改列名?
要更改列名,请在列名后使用AS关键字。首先,让我们创建一个表 –
mysql> create table DemoTable
(
Id int,
StudentFirstNameInCollege varchar(100)
);
Query OK, 0 rows affected (0.68 sec)
使用插入命令将数据插入表中 –
mysql> insert into DemoTable values(100,'Chris');
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable values(101,'Bob');
Query OK, 1 row affected (0.21 sec)
mysql> insert into DemoTable values(102,'David');
Query OK, 1 row affected (0.21 sec)
使用select语句显示表中所有记录 –
mysql> select *from DemoTable;
这将产生以下输出 –
+------+---------------------------+
| Id | StudentFirstNameInCollege |
+------+---------------------------+
| 100 | Chris |
| 101 | Bob |
| 102 | David |
+------+---------------------------+
3 rows in set (0.00 sec)
以下是使用AS关键字在MySQL中更改列名的查询 –
mysql> select Id,StudentFirstNameInCollege AS Name from DemoTable;
这将产生以下输出 –
+------+-------+
| Id | Name |
+------+-------+
| 100 | Chris |
| 101 | Bob |
| 102 | David |
+------+-------+
3 rows in set (0.00 sec)
阅读更多:MySQL 教程