开发者

How to set a trigger which update a field after insertion

开发者 https://www.devze.com 2023-03-04 18:14 出处:网络
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

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

精彩评论

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