自己写的数据库插入时的触发器

create trigger Fittings_Insert_Tr ON Fittings
instead  of  insert 
as
declare
@f_name varchar(50),
@f_no1 varchar(50),
@f_no2 varchar(50),
@b_id int,
@t_id int,
@p_id int,
@f_size varchar(50),
@f_remark varchar(500),
@f_photograpt varchar(500),
@f_amount int
begin
	select @f_name=f_name,@f_no1=f_no1,@f_no2=f_no2,@b_id=b_id,@t_id=t_id,@p_id=p_id,@f_size=f_size,@f_remark=f_remark,@f_photograpt=f_photograpt,@f_amount=f_amount from inserted
	if not exists(select * from  Fittings where f_name=@f_name and f_no1=@f_no1 and f_no2=@f_no2 and b_id=@b_id and t_id=@t_id and p_id=@p_id) 
	begin    	
		insert Fittings (
			f_name,f_no1,f_no2,b_id,t_id,p_id,f_sort,f_commend,f_uploadTime,f_updatetime,f_availabilitytime,f_amount,f_size,f_state,f_minprice,f_price,f_remark,f_locus,f_photograpt
		) select 
			f_name,f_no1,f_no2,b_id,t_id,p_id,'CT','否',getdate(),getdate(),365,f_amount,f_size,'未测试',0,0,f_remark,f_locus,f_photograpt
		 from inserted
	end
	else
	begin
		update Fittings set f_size=@f_size , f_remark=@f_remark ,f_photograpt=@f_photograpt , f_amount=f_amount+@f_amount where f_name=@f_name and f_no1=@f_no1 and f_no2=@f_no2 and b_id=@b_id and t_id=@t_id and p_id=@p_id
	end
end
go

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值