当表名“ match”没有用单引号引起来时,MySQL引发错误?

不要使用单引号。您需要在表名匹配周围使用反引号,因为它是MySQL中的保留名。以下是发生的错误:

mysql> select *from match;
ERROR 1064 (42000) : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'match' at line 1

我们首先创建一个表,并使用保留字匹配周围的反引号来修复上述错误的发生,此处用作表名-

mysql> create table `match`
(
   Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   PlayerName varchar(20)
);

使用insert命令在表中插入一些记录。现在,无论在哪里使用保留字,都用反引号包围-

mysql> insert into `match`(PlayerName) values('Chris');
mysql> insert into `match`(PlayerName) values('Bob');
mysql> insert into `match`(PlayerName) values('David');
mysql> insert into `match`(PlayerName) values('Mike');
mysql> insert into `match`(PlayerName) values('Sam');

使用select语句显示表中的所有记录-

mysql> select *from `match`;

这将产生以下输出-

+----+------------+
| Id | PlayerName |
+----+------------+
|  1 | Chris      |
|  2 | Bob        |
|  3 | David      |
|  4 | Mike       |
|  5 | Sam        |
+----+------------+
5 rows in set (0.00 sec)