Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1450
  • Last Modified:

Create trigger for insert UUID()

Ive built a trigger for inserting a new user, but when I try and run the SQL Query I get:-
#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 '' at line 4.

Any ideas What Im doing wrong?

Table is called `users` and there is a coloum called `priID` set to a VARCHAR(255) [Im going to reduce this though!]

Any help, would be appriciated.

Thank you
CREATE TRIGGER users_insert BEFORE INSERT ON `users`
FOR EACH ROW
BEGIN
SET NEW.`priID` = UUID();
END
;

Open in new window

0
tonelm54
Asked:
tonelm54
  • 2
1 Solution
 
tonelm54Author Commented:
Server details are:-
                    MySQL client version: 5.0.51a
0
 
K VDatabase ConsultantCommented:
copy paste this mysql promt / use  Query Browser for create new Trigger:
mysql>
DELIMITER $$
CREATE TRIGGER users_insert BEFORE INSERT ON `users`
FOR EACH ROW
BEGIN
SET NEW.`priID` = UUID();
END
$$
DELIMITER ;
0
 
tcs224694Commented:
U need to use delimiters for wrting procedure in mysql...

See this for reference..

http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html
0
 
tcs224694Commented:
Try this ....(i think a comma must come there in the END)
DELIMITER //
CREATE TRIGGER users_insert BEFORE INSERT ON `users`
FOR EACH ROW
BEGIN
SET NEW.`priID` = UUID();
END;//
DELIMITER ;

Open in new window

0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now