Home >Backend Development >PHP Tutorial >mysql触发器的问题 能否使用触发器控制某字段一旦有值则拒绝更新

mysql触发器的问题 能否使用触发器控制某字段一旦有值则拒绝更新

WBOY
WBOYOriginal
2016-06-23 13:44:221538browse

t1表  有200个字段 其中一个字段叫 f1

某记录被插入t1表的时候  f1字段一定为null

某次更新会将f1字段改为当前时间戳

在此之后     能否控制所有针对这条记录的update语句  一旦语句会更新这个字段值  则拒绝更新

是用触发器还是其他方法   如果用触发器可以 那么应该怎么写呢?>


回复讨论(解决方案)

CREATE TRIGGER upd_check BEFORE UPDATE ON t1   FOR EACH ROW   BEGIN       IF not isnull f1 THEN           SET NEW.f1 = f1;       END IF;   END;

感谢xu大     `

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn