我们可以使用"year"作为 MySQL 表中的列吗?
mysqlmysqli database更新于 2025/12/10 13:00:17
是的,您可以将年份作为 MySQL 表中的列名,因为它不是保留字。让我们首先创建一个表 −
mysql> create table DemoTable ( Year int ); Query OK, 0 rows affected (0.87 sec)
使用 insert 插入命令在表中插入一些记录 −
mysql> insert into DemoTable values(1995); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(2019); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(2016); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(2018); Query OK, 1 row affected (0.13 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable;
这将产生以下输出 −
+------+ | Year | +------+ | 1995 | | 2019 | | 2016 | | 2018 | +------+ 4 rows in set (0.00 sec)
以下是从 MySQL 表中选择"year"命名列的查询 −
mysql> select year from DemoTable;
这将产生以下输出 −
+------+ | year | +------+ | 1995 | | 2019 | | 2016 | | 2018 | +------+ 4 rows in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

