开发者

How to set a trigger which update a field after insertion

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜