MySQL练习05
创始人
2024-12-11 22:33:28
0

题目

步骤 

触发器

use mydb16_trigger;    #使用数据库  create table goods( gid char(8) primary key, name varchar(10), price decimal(8,2), num int);  create table orders( oid int primary key auto_increment, gid char(10) not null, name varchar(10), price decimal(8,2), onum int, otime date);

添加数据 

insert into goods values ('A0001','橡皮',2.5,100), ('B0001','小楷本',2.8,210), ('C0001','铅笔',1.2,120), ('D0001','计算器',28,20);

输入触发器 

create trigger insert_after_orders_trigger after insert on orders for each row update goods set num=num-new.onum where gid=new.gid;

删除触发器

create trigger delete_after_orders_trigger after delete on orders for each row update goods set num=num+old.onum where gid=old.gid;

更新触发器 

create trigger update_after_orders_trigger after update on orders for each row update goods set num=num+(old.onum-new.onum) where gid=new.gid;

  存储过程

存储过程s1 

delimiter //    #切换命令分隔符 create procedure s1() begin           select name '姓名',incoming '工资' from emp_new; end // delimiter ;

存储过程s2 

delimiter //    #更改命令结束符 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 // delimiter ;

存储过程s3 

delimiter // create procedure s3(in in_dept2 int, out avg_sal double(10,2)) begin          select avg(incoming) into avg_sal from emp_new where dept2=in_dept2; end // delimiter ;

相关内容

热门资讯

分享!微信链接牛牛房卡怎么买/... 牛牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:33699510许多玩家在游戏中会购买房卡来享受...
分享!有没有卖炸金花链接房卡/... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:33699510许多玩家在游戏中会购买房卡来享...
分享!微信好友炸金花房卡如何购... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:33699510许多玩家在游戏中会购买房卡来享...
分享!买房卡的链接炸金花房卡/... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:33699510许多玩家在游戏中会购买房卡来享...
分享!微信玩炸金花房卡怎么买/... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:33699510许多玩家在游戏中会购买房卡来享...
分享!炸金花房卡链接如何购买/... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:33699510许多玩家在游戏中会购买房卡来享...
分享!炸金花房卡如何购买/微信... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:33699510许多玩家在游戏中会购买房卡来享...
分享!斗牛链接房卡怎么搞/皇豪... 斗牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:33699510许多玩家在游戏中会购买房卡来享受...
分享!玩炸金花房卡从哪里买/新... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:33699510许多玩家在游戏中会购买房卡来享...
终于找到“金花房卡平台购买联系... 新全游牛牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:44346008许多玩家在游戏中会购买房卡...
一分钟推荐“金花房卡在哪获取/... 美猴王牛牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:86909166许多玩家在游戏中会购买房卡...
一分钟了解“微信斗牛房卡怎么来... 微信斗牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:86909166许多玩家在游戏中会购买房卡来...
微信链接斗牛房卡充值购买/微信... 斗牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:86909166许多玩家在游戏中会购买房卡来享受...
牛牛金花房卡是如何购买的/微信... 牛牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:160470940许多玩家在游戏中会购买房卡来享...
微信群金花房卡链接如何获得/微... 金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:44346008许多玩家在游戏中会购买房卡来享受...
怎么购买微信炸金花房卡/哪里购... 微信炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:160470940许多玩家在游戏中会购买房...
ia实测“炸金花房卡链接多少钱... 天王大厅是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:44346008许多玩家在游戏中会购买房卡来...
秒懂教程“购买斗牛金花房卡联系... 狂飙大厅是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:86909166许多玩家在游戏中会购买房卡来...
微信炸金花房间房卡在哪里可以玩... 微信炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:86909166许多玩家在游戏中会购买房卡...
微信链接金花房卡怎么弄/微信金... 金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:160470940许多玩家在游戏中会购买房卡来享...