我们可以在 MySQL 表中使用“year”作为列名称吗?


是的,你可以在 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)

更新于:25-Sep-2019

126 次浏览

开始您的 职业

通过完成课程获得认证

开始学习
广告
© . All rights reserved.