I'd like first introduce my requirement. I have a batch file which will execute a Textfile of sql. And I need the function that the program will first check the count of a table, if it is 0, then insert rows. In the following is my code. I was told error:
RROR 1064 (42000) at line 15: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
nnear 'IF @a>0
THEN
INSERT IGNORE INTO `martin1` (`col1`, `col2`) VALUES (1, 'aaa'),(' at line 1
Allthough I have tried some other ways such as adding ";",deleting ";", but it still does not work.
SET @a=(SELECT count(*) FROM `martin1`);
IF @a>0
THEN
INSERT IGNORE INTO `martin1` (`col1`, `col2`) VALUES (1, 'aaa'),(2, 'bbb');
END IF;