--查询数据
select * from test1;
select * from test1_log;
--删除数据
delete from test1;
delete from test1_log;

--添加字段
ALTER TABLE guofeng.test1 ADD ( times TIMESTAMP );

insert into guofeng.test1(id,user,pswd,times) values (2,'lisi','123',CURRENT_TIMESTAMP);
insert into guofeng.test1(id,user,pswd,times) values (3,'wangwu','123',CURRENT_TIMESTAMP);
insert into guofeng.test1(id,user,pswd,times) values (4,'zhaoliu','123',CURRENT_TIMESTAMP);
insert into guofeng.test1(id,user,pswd,times) values (5,'ss','123',CURRENT_TIMESTAMP);
insert into guofeng.test1(id,user,pswd,times) values (6,'ss1111','123',CURRENT_TIMESTAMP);
insert into guofeng.test1(id,user,pswd,times) values (7,'ss1111','123',CURRENT_TIMESTAMP);
insert into guofeng.test1(id,user,pswd,times) values (8,'ss1111','123',CURRENT_TIMESTAMP);
insert into guofeng.test1(id,user,pswd,times) values (9,'ss1111','123',CURRENT_TIMESTAMP);
insert into guofeng.test1(id,user,pswd,times) values (11,'ss1111','123',CURRENT_TIMESTAMP);
insert into guofeng.test1(id,user,pswd,times) values (24,'zhangsan','123',CURRENT_TIMESTAMP);
insert into guofeng.test1(id,user,pswd,times) values (25,'zhangsan','123',CURRENT_TIMESTAMP);
insert into guofeng.test1(id,user,pswd,times) values (26,'zhangsan','123',CURRENT_TIMESTAMP);

update test1 set user = 'lis1231' where id = '2';
update test1 set user = 'lis1232' where id = '2';
update test1 set user = 'lis1233' where id = '2';
update test1 set user = 'lis1234' where id = '2';
update test1 set user = 'lis1235' where id = '2';

delete from test1 where id = '25';
delete from test1 where id = '26';

--日志表序列
CREATE SEQUENCE test1_log_SEQ;

--更新触发器
DROP TRIGGER TEST1_TRIGGER_VAR_UPDATE;
CREATE TRIGGER TEST1_TRIGGER_VAR_UPDATE                   
AFTER UPDATE ON test1                                   
REFERENCING NEW ROW mynewrow, OLD ROW myoldrow          
FOR EACH ROW                                             
BEGIN
INSERT INTO test1_log(id,type,befare,after) VALUES(test1_log_SEQ.NEXTVAL,'u'
,:myoldrow.id||','||:myoldrow.user||','||:myoldrow.pswd||','||:myoldrow.times
,:mynewrow.id||','||:mynewrow.user||','||:mynewrow.pswd||','||:mynewrow.times); 
END;

--插入触发器
DROP TRIGGER TEST1_TRIGGER_VAR_INSERT;
CREATE TRIGGER TEST1_TRIGGER_VAR_INSERT                   
AFTER INSERT ON test1                                   
REFERENCING NEW ROW mynewrow
BEGIN
INSERT INTO test1_log(id,type,befare) VALUES(test1_log_SEQ.NEXTVAL,'c'
,:mynewrow.id||','||:mynewrow.user||','||:mynewrow.pswd||','||:mynewrow.times);
END;

--删除触发器
DROP TRIGGER TEST1_TRIGGER_VAR_DELETE;
CREATE TRIGGER TEST1_TRIGGER_VAR_DELETE                   
AFTER DELETE ON test1                                   
REFERENCING OLD ROW myoldrow
BEGIN
INSERT INTO test1_log(id,type,befare) VALUES(test1_log_SEQ.NEXTVAL,'d'
,:myoldrow.id||','||:myoldrow.user||','||:myoldrow.pswd||','||:myoldrow.times);
END;
