执行时出现SQL语法错误

时间:2013-10-01 09:55:06

标签: sql if-statement not-exists

我已经尝试了所有可能对语法产生影响的内容,但没有任何效果。我想运行此脚本以向名为pm_Permissions的表添加条目。但是,当我再次运行它并且该条目已经存在时,我不希望它再次添加。

IF NOT EXISTS (SELECT 1 FROM pm_Permissions WHERE permission_tag = 'dbcorrectstructure')
BEGIN

    LOCK TABLES `pm_Permissions` WRITE;
    /*!40000 ALTER TABLE `pm_Permissions` DISABLE KEYS */;
    INSERT INTO `pm_Permissions` VALUES (NULL,'dbCorrectStructure', 'Makes sure all the correct tables, columns and entries exist','dbcorrectstructure','$sourcedir/administration.lib.php','dbCorrectStructure','Administration',0);
    /*!40000 ALTER TABLE `pm_Permissions` ENABLE KEYS */;
    UNLOCK TABLES;

END

提前致谢。

1 个答案:

答案 0 :(得分:0)

(SELECT 1 FROM pm_Permissions WHERE permission_tag = 'dbcorrectstructure') 

此处为permission_tag = 'dbcorrectstructure',但在您插入时'dbCorrectStructure' ...

这是正确的吗?我认为你应该匹配案例..

您应该像(SELECT 1 FROM pm_Permissions WHERE permission_tag = 'dbCorrectStructure')

一样检查