是的,您可以在MySQL表中以年份作为列名,因为它不是保留字。让我们首先创建一个表-mysql> create table DemoTable
(
Year int
);
使用插入命令在表中插入一些记录-mysql> insert into DemoTable values(1995);
mysql> insert into DemoTable values(2019);
mysql> insert into DemoTable values(2016);
mysql> insert into DemoTable values(2018);
使用select语句显示表中的所有记录-mysql> select *from DemoTable;
这将产生以下输出-+------+
| Year |
+------+
| 1995 |
| 2019 |
| 2016 |
| 2018 |
+------+
4 rows in set (0.00 sec)
以下是从MySQL表中选择“年份”命名列的查询-mysql> select year from DemoTable;
这将产生以下输出-+------+
| year |
+------+
| 1995 |
| 2019 |
| 2016 |
| 2018 |
+------+
4 rows in set (0.00 sec)