表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
------解决方案--------------------
------解决方案--------------------
- 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