SQL Syntex Parse Error..

[expired user #9296]'s profile image [expired user #9296] posted 9 years ago in Running SQL scripts Permalink
DROP TRIGGER IF EXISTS trgInsertA_SomeTable;
CREATE TRIGGER trgInsertA_SomeTable AFTER INSERT ON SomeTable
FOR EACH ROW BEGIN
-- -------------------------------------------------------
-- Comment
-- -------------------------------------------------------
DECLARE __SomeColumn VARCHAR(3) DEFAULT '0'; -- Column Comment

-- to do...
END;


SQL Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 8

[expired user #9296]'s profile image [expired user #9296] posted 9 years ago Permalink

DROP TRIGGER IF EXISTS trgInsertA_SomeTable;
CREATE TRIGGER trgInsertA_SomeTable AFTER INSERT ON SomeTable
FOR EACH ROW BEGIN
-- -------------------------------------------------------
-- Comment
-- -------------------------------------------------------
DECLARE __SomeColumn VARCHAR(3) DEFAULT '0'; -- Column Comment

-- to do...
END;


SQL Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 6

ansgar's profile image ansgar posted 9 years ago Permalink
HeidiSQL splits queries at semicolons by default. Your CREATE TRIGGER query has a semicolon within itself. Look at the line which ends with "... DEFAULT '0';"

You need to change the query delimiter for HeidiSQL, so it's not semicolon but something else. You can either change the delimiter using the button with the red semicolon on it, on the main toolbar. Or by adding a client-side DELIMITER command:
DELIMITER //
DROP TRIGGER... //
CREATE TRIGGER trgInsertA_SomeTable AFTER INSERT ON SomeTable
FOR EACH ROW BEGIN
DECLARE __SomeColumn VARCHAR(3) DEFAULT '0'; -- Column Comment
-- to do...

END//
DELIMITER ;
[expired user #9296]'s profile image [expired user #9296] posted 9 years ago Permalink
thank a lot..
Have a good day!!

Please login to leave a reply, or register at first.