准备:
1 创建日志表
DROP TABLE IF EXISTS `demo`;
CREATE TABLE `demo` (
`id` int DEFAULT NULL,
`name` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `logs`;
CREATE TABLE `logs` (
`code` varchar(32) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `demo` VALUES ('2', 'zz');
INSERT INTO `demo` VALUES ('1', 'yy');
INSERT INTO `demo` VALUES ('3', 'sz');
1 视图
视图创建
create view v_user as select * from demo;
视图
select * from v_user;
2 触发器
创建触发器
DELIMITER ||
CREATE TRIGGER demo BEFORE INSERT
ON demo FOR EACH ROW
BEGIN
INSERT INTO logs VALUES(NOW());
END
||
DELIMITER ;
测试
INSERT INTO `demo` VALUES ('1', 'a');
结果
`logs` 表中有数据
select * from `logs`
3 存储过程
创建
DELIMITER ||
CREATE PROCEDURE delete_proc(IN p_playerno INTEGER)
BEGIN
DELETE FROM demo
WHERE id = p_playerno;
END
||
测试
call delete_proc(1);
查询
select * from demo