假如下面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所有记录,再插入一条新记录。
各位高手指教下!感谢!

解决方案 »

  1.   

    三个表互不相干,得把所有需要的参数都传进来才行:
    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,@yy2end