14 MySQL 内置功能--视图/触发器
#视图
select * from course inner join teacher on course.teacher_id=teacher.tid; create view course2teacher as select * from course inner join teacher on course.teacher_id=teacher.tid;
#触发器
CREATE TABLE cmd ( id INT PRIMARY KEY auto_increment, USER CHAR (32), priv CHAR (10), cmd CHAR (64), sub_time datetime, #提交时间 success enum (‘yes‘, ‘no‘) #0代表执行失败 ); CREATE TABLE errlog ( id INT PRIMARY KEY auto_increment, err_cmd CHAR (64), err_time datetime ); #创建触发器 delimiter // CREATE TRIGGER tri_after_insert_cmd AFTER INSERT ON cmd FOR EACH ROW BEGIN IF NEW.success = ‘no‘ THEN #等值判断只有一个等号 INSERT INTO errlog(err_cmd, err_time) VALUES(NEW.cmd, NEW.sub_time) ; #必须加分号 END IF ; #必须加分号 END// delimiter ;
#存储过程
delimiter // create procedure p1() BEGIN select * from db7.teacher; END// delimiter; #有参存储过程 delimiter // create procedure p2(in n1, in n2 int, out res int) BEGIN select * from db7.teacher where tid>n1 and tid<n2; set res=1; END// delimiter; #MySQL中调用 set @x=0 call p2(2,4,@x); #python 中调用
相关推荐
zjuwangleicn 2020-06-25
debugjoker 2020-06-17
昊 2020-06-16
sunnyxuebuhui 2020-06-14
hanshangzhi 2020-06-14
ncomoon 2020-06-14
hanshangzhi 2020-06-12
wudaokouer 2020-04-16
一昕之代码 2020-02-20
李轮清 2020-05-11
URML 2020-05-10
nimeijian 2020-05-06
lpfvip00 2020-04-26
lt云飞扬gt 2020-04-21
书弋江山 2020-04-19
dayi 2020-04-11
daillo 2020-04-07
Accpcjg 2020-03-05