建立表時設定表名“references”時,將出現錯誤


你無法給表名引用,因為它是一個保留關鍵字。用反引號將它包起來,例如,`references`。

讓我們先建立一個表格 -

mysql> create table `references`(Subject text);
Query OK, 0 rows affected (0.44 sec)

使用 insert 命令在表中插入一些記錄 -

mysql> insert into `references` values('Introduction To MySQL');
Query OK, 1 row affected (0.28 sec)
mysql> insert into `references` values('Introduction To MongoDB');
Query OK, 1 row affected (0.15 sec)
mysql> insert into `references` values('Introduction To Spring and Hibernate');
Query OK, 1 row affected (0.13 sec)
mysql> insert into `references` values('Introduction To Java');
Query OK, 1 row affected (0.18 sec)

使用 select 語句顯示錶中的所有記錄 -

mysql> select *from `references`;

這將產生以下輸出 -

+--------------------------------------+
| Subject                              |
+--------------------------------------+
| Introduction To MySQL                |
| Introduction To MongoDB              |
| Introduction To Spring and Hibernate |
| Introduction To Java                 |
+--------------------------------------+
4 rows in set (0.00 sec)

更新於: 2019-08-21

107 瀏覽

開啟你的職業生涯

完成課程以獲得認證

開始
廣告