1
SELECT COUNT(*) INTO @count FROM `tableName` WHERE `id` = OLD.id;

WHILE @count > -1 DO
    SET @count = @count - 1;
    /* loop logic in here */
END WHILE;

I have this SQL but when I run it I get an error (SQL Syntax) that MySQL says is near the WHILE @count > -1 DO SET @count = @count - 1;. I've tried wrapping the while in a BEGIN ... END; block but that doesn't affect it at all.

Due to MySQL's brilliantly vague errors I can't work out what I've done wrong.

I'm sure it's very simple but it's late and I can't spot it for the life of me.

2
  • Isn't @count of type table instead of an int? I think you want to use select @count=count(*) from tableName... Commented Mar 8, 2011 at 2:39
  • How do you run this code? From what I see it's supposed to be inside the trigger body. Commented Mar 8, 2011 at 2:41

1 Answer 1

5

You cannot just run this code in mysql client command line. You can use compound statements in the body of Stored procedures/Functions or Triggers

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.