Create trigger to add UUID() value to a field when record insert

Hello,

I added a field to my users table, the field name is uuid, and I want to create a trigger that activates on insert and set the uuid value for that new inserted record to the function UUID(). I tried this, but no success


CREATE TRIGGER uuid_users_insert BEFORE INSERT ON `users`
FOR EACH ROW
BEGIN
SET NEW.uuid = UUID();
END
;

I get this error:

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 ‘’ at line 4
Any idea?

http://dev.mysql.com/doc/refman/5.1/en/begin-end.html

Use of multiple statements requires that a client is able to send statement strings containing the ; statement delimiter. This is handled in the mysql command-line client with the delimiter command. Changing the ; end-of-statement delimiter (for example, to //) allows ; to be used in a routine body. For an example, see Section 18.2.1, “CREATE PROCEDURE and CREATE FUNCTION Syntax”.

I found a way…


CREATE TRIGGER init_uuid_users BEFORE INSERT  ON users
FOR EACH
ROW  SET NEW.uuid = UUID(  ) ;

This one worked…

Doing this doesn’t delay or slows down the performance of MySQL, right?