当表名“ 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)
热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便