mysql触发器实例 插入数据时触发
时间:2015-02-22 14:55 来源:linux.it.net.cn 作者:IT
分享一个mysql触发器的例子,代码如下:
create table test(
percent decimal
);
delimiter $$
CREATE TRIGGER test_before_insert
BEFORE INSERT ON test FOR EACH ROW
BEGIN
IF NEW.percent < 0.0 OR NEW.percent > 1.0 THEN
SET NEW.percent = NULL;
END IF;
END$$
delimiter ;
drop trigger test_before_insert;
drop table test;
(责任编辑:IT)
分享一个mysql触发器的例子,代码如下: create table test( percent decimal ); delimiter $$ CREATE TRIGGER test_before_insert BEFORE INSERT ON test FOR EACH ROW BEGIN IF NEW.percent < 0.0 OR NEW.percent > 1.0 THEN SET NEW.percent = NULL; END IF; END$$ delimiter ; drop trigger test_before_insert; drop table test;(责任编辑:IT) |