示例一:
DELIMITER //
CREATE TRIGGER InsertUser
beforeinsert ON USER
FOR EACH ROW
BEGIN
INSERT INTO user_group(uid,gid)VALUES(new.uid,'group4444444444');
END;//
DELIMITER ;
示例二:
DELIMITER //
CREATE TRIGGER InsertUser
beforeinsert ON USER
FOR EACH ROW
BEGIN
IF new.Type=2 THEN
INSERT INTO user_group(uid,gid)VALUES(new.uid,'group4444444444');
ELSE
INSERT INTO user_group(uid,gid)VALUES(new.uid,'group55555555555')
END IF;
END;//
DELIMITER ;
示例三:
DELIMITER //
CREATE TRIGGER InsertUser
beforeinsert ON USER
FOR EACH ROW
BEGIN
IF new.type=1 THEN
INSERT INTO user_group(uid,gid)VALUES(new.uid,'578d3369633b47bd9c1fe8bf905cbfb1');
END IF;
IF new.type=2 THEN
INSERT INTO user_group(uid,gid)VALUES(new.uid,'387bcd57fc5a4c3c9de83ee210fef661');
END IF;
END;//
DELIMITER ;
示例四:
DELIMITER //
CREATE TRIGGER EhrUserInsert
AFTER INSERT ON Cube_EHRUser
FOR EACH ROW
BEGIN
SET @start_time=NOW();
SET @num=(SELECT COUNT(1) FROM Cube_Map WHERE EHR_pos_no=new.Jobcode);
SET @cou=(SELECT COUNT(1) FROM Cube_EHRUserChange WHERE jobcode=new.Jobcode AND add_time=@start_time);
IF (@num=0 AND @cou=0) THEN
INSERT INTO `Cube_EHRUserChange`(jobcode,is_send,add_time) VALUES(new.Jobcode,0,@start_time);
END IF;
END;//
DELIMITER ;
MySQL之触发器
最新推荐文章于 2021-11-26 11:51:00 发布