[b]业务逻辑:[/b]表myupload做了增加、修改、删除时,在表myuploaddaybook新增一条用来记录myupload表变化的行。
[b]myupload表[/b]
[b]myuploaddaybook表[/b]
[b]before insert[/b]
[b]before Update[/b]
[b]before delete[/b]
------------------------------
查看触发器:
删除触发器:
[b]myupload表[/b]
CREATE TABLE `myupload` (
`uploadid` int(11) NOT NULL AUTO_INCREMENT,
`bookid` int(11) DEFAULT NULL,
`numb` int(11) DEFAULT NULL,
`saleuserid` int(11) DEFAULT NULL,
`trdate` varchar(20) DEFAULT NULL,
`state` char(1) DEFAULT NULL,
`remark` varchar(255) DEFAULT NULL,
PRIMARY KEY (`uploadid`)
) ENGINE=InnoDB AUTO_INCREMENT=856 DEFAULT CHARSET=utf8;
[b]myuploaddaybook表[/b]
CREATE TABLE `myuploaddaybook` (
`uploadid` int(11) NOT NULL AUTO_INCREMENT,
`bookid` int(11) DEFAULT NULL,
`numb` int(11) DEFAULT NULL,
`saleuserid` int(11) DEFAULT NULL,
`trdate` varchar(20) DEFAULT NULL,
`mng` varchar(20) DEFAULT NULL,
PRIMARY KEY (`uploadid`)
) ENGINE=InnoDB AUTO_INCREMENT=856 DEFAULT CHARSET=utf8;
[b]before insert[/b]
create trigger mydb_insert_trigger
before insert On myupload
for each row
insert into myuploaddaybook(bookid,saleuserid,numb,trdate,mng)
values(new.bookid,new.saleuserid,new.numb ,new.trdate,'insert')
[b]before Update[/b]
Create Trigger mudb_update_trigger
before Update On myupload
for each row
insert into myuploaddaybook(bookid,saleuserid,numb,trdate,mng)
values(old.bookid,old.saleuserid,new.numb ,new.trdate,'update')
[b]before delete[/b]
create trigger mydb_del_trigger
before delete On myupload
for each row
insert into myuploaddaybook(bookid,saleuserid,numb,trdate,mng)
values(old.bookid,old.saleuserid,old.numb ,old.trdate,'delete')
------------------------------
查看触发器:
show triggers;
删除触发器:
drop TRIGGER mydb_del_trigger;