关于触发器的问题
我刚自学了触发器,想做一个药的数据库目的是向入库清单中插入数据的时候,希望药库也相应改变
可是只能改变第一次插入入库清单时的药品,不知道为什么,请指教
if object_id('Trigger1','TR')is not null
drop Trigger Trigger1;
go
create trigger Trigger1 on 入库清单
after insert
as
declare @number int,@name varchar(15);
select @number=medician_number,@name=medician_name from inserted
if(@name not in(select medician_name from 药库))
begin
insert into 药库(medician_name,medician_store,修改日期)
select @name,@number,date
from inserted
end
else
begin
insert into 药库
select @name,@number+medician_store,date
from inserted,药库
where @name=药库.medician_name and 修改日期=(select top 1
修改日期 from 药库 order by 修改日期 desc)
end
go