假设我们尝试创建名称为“ 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
为了创建带有保留关键字的表,您需要使用backticks(``)的概念。
让我们创建一个表-mysql> create table `groups`
-> (
−> id int,
−> name varchar(40)
−> )
−> ;
借助insert命令将一些记录插入表中-mysql> insert into `groups` values(10,'John');
mysql> insert into `groups` values(11,'Bob');
mysql> insert into `groups` values(12,'Mike');
使用select语句显示表中的记录mysql> select *from `groups`;
这将产生以下输出-+------+------+
| id | name |
+------+------+
| 10 | John |
| 11 | Bob |
| 12 | Mike |
+------+------+
3 rows in set (0.04 sec)