首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

当一表中A列插入时更新2表信息 当1表中B列插入时更新2表信息

2012-09-06 
当1表中A列插入时更新2表信息当1表中B列插入时更新2表信息表1create table 临时卡(卡号 int not null,进库

当1表中A列插入时更新2表信息 当1表中B列插入时更新2表信息
表1
 create table 临时卡
  (
卡号 int not null ,
进库时间 datetime not null ,
车库名称 varchar(30),
出库时间 datetime not null ,
消费金额 money not null
  )
表2
 create table 停车场信息
  (
名称 varchar(20) primary key,
车位总数 int,
已停车位 int,
预约车位 int,
剩余车位 int
  )
进库,出库分别更新停车场信息的已停和剩余


[解决办法]

SQL code
CREATE trigger [trigger_1] on [dbo].[table1]  instead   of  update  as begin    if update(A) begin      更新 table2  end     if update(B) begin      更新 table2  end   end
[解决办法]
探讨
老大,您回复真及时,解决了定给高分。
俺的CREATE trigger [trigger_1] on [dbo].[临时卡]
instead of update
as begin
if update(进库时间) begin
update 停车场信息 set 剩余车位=剩余车位-1
where 名称=(select 车库名称 from inserted)
……

[解决办法]
SQL code
CREATE trigger [trigger_1] on [dbo].[临时卡]   instead of update   as begin     if update(进库时间) begin     update 停车场信息 set 剩余车位=剩余车位-1  where 名称= inserted.车库名称  update 停车场信息 set 已停车位=已停车位+1  where 名称=inserted.车库名称  end     if update(出库时间) begin         update 停车场信息 set 剩余车位=剩余车位+1  where 名称=inserted.车库名称  update 停车场信息 set 已停车位=已停车位-1  where 名称=inserted.车库名称  end   end
[解决办法]
SQL code
CREATE trigger [trigger_1] on [dbo].[临时卡]   instead of update   as begin     if update(进库时间)  begin     update 停车场信息 set 剩余车位=剩余车位-1 , 已停车位=已停车位+1         where 名称= inserted.车库名称 end     if update(出库时间)  begin       update 停车场信息 set 剩余车位=剩余车位+1,已停车位=已停车位-1           where 名称=inserted.车库名称 end   end 

热点排行
Bad Request.