一个简单的SQL SERVER insert触发器
alter trigger material_trigger
on tb04_material for insert
as
begin
declare @materialId int
select @materialId=i.material_id from inserted i
declare @G_StatisticsId int
exec @G_StatisticsId = sp_GetUniqueID 'tb04_statistics',@G_StatisticsId
declare @dateNow datetime
declare @year int
declare @month int
set @dateNow=getdate()
set @year=year(@dateNow)
set @month=month(@dateNow)
insert into tb04_statistics(id,year,month,begin_value,end_value,material_id)
values(@G_StatisticsId,@year,@month,0,NULL,@materialId)
end
on tb04_material for insert
as
begin
declare @materialId int
select @materialId=i.material_id from inserted i
declare @G_StatisticsId int
exec @G_StatisticsId = sp_GetUniqueID 'tb04_statistics',@G_StatisticsId
declare @dateNow datetime
declare @year int
declare @month int
set @dateNow=getdate()
set @year=year(@dateNow)
set @month=month(@dateNow)
insert into tb04_statistics(id,year,month,begin_value,end_value,material_id)
values(@G_StatisticsId,@year,@month,0,NULL,@materialId)
end

浙公网安备 33010602011771号