如果尚未存在mysql插入

时间:2015-08-17 21:05:28

标签: mysql

我试图在MySQL表中插入一些东西,但只有它还不存在

从其他帖子我找到了这个解决方案:

IF NOT EXISTS (SELECT * FROM `settings` WHERE `name`= 'disable_new_user')
BEGIN
    INSERT INTO `settings` (`id`, `name`, `state`) VALUES (NULL, 'disable_new_user', 'true')
END

然而,这给了我一条错误消息:

#1064 - 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 'IF NOT EXISTS (SELECT * FROM `settings` WHERE `name`= 'disable_new_user') BEGIN' at line 1

0 个答案:

没有答案