MYSQL语法分隔符和语法错误

时间:2014-12-09 09:58:46

标签: mysql

我已尝试修复以下语法错误,但我无法看到这里的错误:

DELIMITER =
CREATE TRIGGER trigs BEFORE UPDATE ON autoinc 
FOR EACH ROW BEGIN 
DECLARE num_rows INTEGER; 
SELECT (*) INTO num_rows FROM autoinc;
IF num_rows >=3 THEN 
DELETE FROM autoinc LIMIT 1; 
END IF; 
END=
DELIMITER ;

错误是:

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 '*) INTO num_rows FROM autoinc; IF num_rows >' at line 4

 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 '3 THEN 

有什么可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

正如评论中已经提到的那样:

SELECT (*) AS num_rows ...

可能意味着

SELECT COUNT(*) AS num_rows ...

IF num_rows >=3 THEN 

在您将=定义为分隔符时中断。

使用代码中没有出现的分隔符,例如:

DELIMITER //

通过这两项更改,事情应该没有语法错误