I have a table called list which has a id,name and size. Size stores the length of the name 开发者_C百科field. I want to update this field after insertion. In other words, Trigger after insert ( yes I can do in the code but I just curios about it) Any suggestions?
You should use a BEFORE INSERT trigger. Use the keyword new to refer to the columns about to be inserted:
CREATE TRIGGER my_trigger BEFORE INSERT ON list FOR EACH ROW BEGIN SET NEW.size = LENGTH(NEW.name)
精彩评论