I have the following MYSQL query:
START TRANSACTION;
SELECT sport_id INTO @a FROM sports WHERE sport_id = 2 FOR UPDATE;
UPDATE sports SET sport_name = 'Table Tennis' WHERE sport_id = @a;
if (@a > 1) then
COMMIT;
ELSE
ROLLBACK;
END IF;
The problem is that it returns an error at the if statement:
#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 (@a > 1) then COMMIT' at line 1
I've looked on stack overflow and there is an answer showing a similar query, written in pretty much the same way, but they are using the variable without an @
symbol. Removing the @
for my query does not resolve the issue.
This is just a test query to try out some transactions using MYSQL, hence why the query seems a little pointless. I'm a little stuck.