
假设我们尝试创建一个名为“groups”的表,这是 MySQL 中的保留关键字。您不能使用“groups”,因为 groups 是 MySQL 中的保留关键字。 创建名为“groups”的表时发生以下错误 -mysql> create table groups
−> (
−> id int,
−> name varchar(40)
−> );
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 'groups
(
id int,
name varchar(40)
)' at line 1 登录后复制 为了创建带有保留关键字的表,您需要使用反引号(``)的概念。 让我们创建一个表 - mysql> create table `groups`
-> (
−> id int,
−> name varchar(40)
−> )
−> ;
Query OK, 0 rows affected (3.08 sec) 登录后复制 使用插入命令将一些记录插入到表中 − mysql> insert into `groups` values(10,'John');
Query OK, 1 row affected (0.30 sec)
mysql> insert into `groups` values(11,'Bob');
Query OK, 1 row affected (0.32 sec)
mysql> insert into `groups` values(12,'Mike');
Query OK, 1 row affected (0.40 sec) 登录后复制 使用select语句显示表中的记录 mysql> select *from `groups`; 登录后复制 这将产生以下输出 − +------+------+
| id | name |
+------+------+
| 10 | John |
| 11 | Bob |
| 12 | Mike |
+------+------+
3 rows in set (0.04 sec) 登录后复制 |