创建表时设置表名"references"时出错
mysqlmysqli database更新于 2023/10/23 6:46:00
您不能给出表名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)