我就是插了代码后,出问题了
我在StockRecord表插入了数据后,触发器起作用,Storage表的Amount增加了;接着在Bank表插入了数据后,触发器起作用,User表的Cash增加;但是我接着在SellRecord表中插入数据,触发器就不起作用了;
好像是只能用一个一样,我要是先在SellRecord表中插入数据,User表的Cash减少,Storage表的Amount减少; 要是再接着向StockRecord表或Bank表插入数据,触发器就没用了;反过来接着不管向那个表插数据都触发器都不起作用了。反过来插也一样
我在StockRecord表插入了数据后,触发器起作用,Storage表的Amount增加了;接着在Bank表插入了数据后,触发器起作用,User表的Cash增加;但是我接着在SellRecord表中插入数据,触发器就不起作用了;
好像是只能用一个一样,我要是先在SellRecord表中插入数据,User表的Cash减少,Storage表的Amount减少; 要是再接着向StockRecord表或Bank表插入数据,触发器就没用了;反过来接着不管向那个表插数据都触发器都不起作用了。反过来插也一样
select @Depot = Depot from inserted
select @Amount = Amount from inserted
select @Pname = Pname from inserted樓主這种語句可以這樣寫:select @Gastype = Gastype ,@Depot = Depot ,@Amount = Amount ,@Pname = Pname from inserted 另外你可以在查詢分析器這樣調試begin tran
insert into ......(這里寫測試語句)
select * from tab 這里寫查詢語句檢查觸發器是否有用
rollback tran ---因執行完後回滾,就算程序出錯也不會留下拉圾,可以修正後重新運行,非常方便然後在要測試的觸發器中用Print 或select 語句檢查是否最入了觸發器,
On SellRecord
After Insert
AsDeclare @Gastype as nvarchar(50)
Declare @Depot as nvarchar(50)
Declare @Amount as float
Declare @Pname as nvarchar(50)
Declare @cur_Amount as float
Declare @Cash as float
Declare @Price as float
declare @count intselect @Gastype = Gastype from inserted
select @Depot = Depot from inserted
select @Amount = Amount from inserted
select @Pname = Pname from inserted
select @price = price from inserted
--select @Price = Price from GasType where type=@Gastype 是不是还有一个Gastype表来存放PRICE,暂时不要了。
--update SellRecord set Price=@Price where Gastype=@Gastypeselect @count=(select count(*) from storage where gastype=@gastype and depot=@depot)
if @count='0'
begin
insert into storage (gastype,depot,amount) values(@gastype,@depot,@amount)
end
else
begin
select @cur_Amount = Amount from Storage where Gastype = @Gastype and Depot = @Depot
Update Storage set Amount = (@cur_Amount-@Amount) where Gastype = @Gastype and Depot = @Depot
end
/*
Select @Cash = Cash from Users where Pname = @Pname
Update Users set Cash = (@Cash-@Amount*@Price) where Pname = @Pname*/
比如说我现触发了个触发器A ,给变量SD+5 ; 再触发触发器B ,给变量SD-5
就像 Trigger AutoProcessSell和Trigger AutoInsertStorage操作表Storage的Amount 一样
一个减,一个加
问题就在
Trigger AutoProcessSell和Trigger AutoInsertStorage 能不能 通过SellRecord 表触发修改Storage 表的Amount 使Amount减少 ;通过SellRecord表触发修改Storage 表的Amount使Amount减少我实在搞不清到底是什么问题 ,望大家帮帮忙 ,给我指出下 小弟在这谢谢大家了
就不再再问A表的触发器可以触发,但B表的触发器不可以触发,
既然你已经可以判断出B表的触发器不可以触发,你就重点在B触发器上找答案了,
另外,我给你写的那个触发器已经可以帮你解决“通过SellRecord 表触发修改Storage 表的Amount 使Amount减少 ”你这个问题,已经帮写你写的够清楚了。