Mysql - 插入带有空格的字符串

时间:2012-04-25 22:39:48

标签: mysql

如何在VARCHAR中插入带空格的字符串?

insert into users (user_id,firstname,lastname,email,group) values('admin','some','Body','admin@something.com','Site admin');

这给了我语法错误,我是mysql的新手,我浏览了mysql文档,并没有让我清楚地知道为什么会出现这种情况。

 mysql> insert into users (user_id,firstname,lastname,email,group) values('admin','some','Body','admin@something.com','Site admin');
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 'group) values('admin','some','Body','admin@something.com','Site admin')' at line 1

2 个答案:

答案 0 :(得分:5)

group是MySQL中的关键字。像这样修改您的查询:

INSERT INTO users (user_id, firstname, lastname, email, `group`)
VALUES('admin', 'some', 'Body', 'admin@something.com', 'Site admin');

答案 1 :(得分:4)

Group是一个关键字,你需要使用像这个`group`这样的返回滴答来使它成为一个表列,而不是

INSERT into users (user_id,firstname,lastname,email,`group`)
VALUES ('admin','some','Body','admin@something.com','Site admin');