我們可以在 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.