在MySQL表中使用“year”作为列名可行吗?

在MySQL表中使用“year”作为列名可行吗?

可以在MySQL表中使用“year”作为列名,因为它不是保留字。先创建一个表-

mysql> create table DemoTable
(
   Year int
);
Query OK, 0 rows affected (0.87 sec)

使用插入命令在表中插入一些记录 –

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 教程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程