+ -
当前位置:首页 → 问答吧 → 存储过程问题

存储过程问题

时间:2011-12-22

来源:互联网

假如下面3个表
教师职员表
IP 姓名 年龄 身高 体重 工资 入校时间 
1 张三 38 1.7 60 3000 2010-2-23
2 小李 35 1.7 70 3500 2002-2-23


中一课程表
IP 语文 数学 英语 
1 1 0 1
1 0 0 1
2 0 1 0

 
中二课程表
IP 语文 数学 英语  
1 1 0 1
1 3 1 0
2 1 1 1

如果用一个存储过程对这3个表同时修改
条件IP=1,工资=3000
教师职员表IP=1更新他所有信息
中一课程表删除IP=1所有记录,再插入一条新记录
中二课程表删除IP=1所有记录,再插入一条新记录。
各位高手指教下!感谢!

作者: qaz9623   发布时间: 2011-12-22

看不出有什么难的啊,找个教程跟着写一写吧

作者: SSXYC   发布时间: 2011-12-22

三个表互不相干,得把所有需要的参数都传进来才行:
SQL code
create procedure updatethreetables
(@ip1 int,@gz int,@ip2 int,@ip3 int,@yw1 int,@sx1 int,@yy1 int,@ip4 int,@ip5 int,@yw2 int,@sx3 int,@yy3 int)
as
begin
update 教师职员表 set 工资=工资+@gz where ip=@ip1
delete 中一课程表 where ip=@ip2
insert into 中一课程表 select @ip3,@yw1,@sx1,@yy1
delete 中二课程表 where ip=@ip4
insert into 中二课程表 select @ip5,@yw2,@sx2,@yy2

end

作者: qianjin036a   发布时间: 2011-12-22

每个表是关系的。
IP是主键!

作者: qaz9623   发布时间: 2011-12-22

每个表是关连的。
IP是主键

作者: qaz9623   发布时间: 2011-12-22