问题详细描述:
入库表(RKB)字段:
编号(BH)、时间(SJ)、入库数量(SL)
出库表(CKB)字段:
编号(BH)、时间(SJ)、出库数量(SL)
库存表(KCB)字段:
编号(BH)、库存数量(SL)
入库表(RKB)、出库表(CKB)都有触发器,实现在插入入库表(RKB)时增加相应编号的库存数量,在插入出库表(CKB)时减少相应编号的库存数量,先就只考虑入库表(RKB)、出库表(CKB)插入的情况。
要拒绝直接的
update KCB
set sl=1
where bh='aaa'
语句。
回答:
在你的入庫表(RKB)、出庫表(CKB)等表的触發器代碼中的一開始加入如下代碼:
declare @temptable varchar(50)
set @temptable = '##temp'+cast(@@spid as varchar)
exec ('create table '+@temptable+'(a1 int)')
在庫存表(KCB)上創建如下的觸發器:
create trigger trigger_KCB on KCB
for insert,update,delete
as
declare @temptable varchar(50)
set @temptable = '##temp'+cast(@@spid as varchar)
if object_id('tempdb.dbo.'+@temptable) is not null
exec ('drop table '+@temptable)
else
rollback