目录
要求
部分代码
触发器
1、mysql> create trigger orders_after_insert_trigger
-> after insert on orders for each row
-> update goods set num=num-new.onum
-> where gid=new.gid;
2、mysql> create trigger orders_after_delete_trigger
-> after delete on orders for each row
-> update goods set num=num+old.onum
-> where gid=old.gid;
3、mysql> create trigger orders_after_update_trigger
-> after update on orders for each row
-> update goods set num = num - new.onum
-> where gid = old.gid ;
存储过程
1、mysql> delimiter //
mysql> create procedure s1()
-> begin
-> select name ,incoming from emp_new;
-> end //
2、mysql> create procedure s2(in in_name varchar(11) , out out_age int )
-> begin
-> select age into out_age from emp_new where name = in_name ;
-> end //
3、mysql> create procedure s3(in in_dept varchar(20) ,out out_avg_incoming int)
-> begin
-> select avg(incoming) into out_avg_incoming from emp_new a join dept b on a.dept2=b.dept1 where dept_name = in_dept;
-> end //