Deadlock at trigger
a trigger need insert or update record @ other table in high traffic environments
however, deadlock happens; ie, trigger running twice @ same time want need insert record @ table.
i trid change isolation serializable or repeatable , cannot solve problem. guess "while loop" affects result because try cancel loop , execute smoothly.
? how solve deadlock???
thx
alex
-----------------------------
i used following commands change isolation level:
set transaction isolation level serializable
begin transaction
commit transaction
-----------------------------
the code follows:
declare setskucursor cursor
local
static
for select item, quantity invset sku = @sku
open setskucursor
fetch next setskucursor @invsetitem, @invsetqty
while @@fetch_status = 0
begin
select @balsku = sku, @opendate = opendate invbal sku = @invsetitem
if (@balsku not null)
begin
if @txdate <= @opendate
update invbal set slsqtynow = slsqtynow + @itmtxqty * @invsetqty sku = @invsetitem
if @txdate > @opendate
update invbal set slsqtynxt = slsqtynxt + @itmtxqty * @invsetqty sku = @invsetitem
end
else
begin
insert invbal (shop, sku, opendate, slsqtynow) values (@shop, @invsetitem, @bizdate, @itmtxqty * @invsetqty)
end
fetch next setskucursor @invsetitem, @invsetqty
end
close setskucursor
deallocate setskucursor
-------------------------------------------------------------------
SQL Server > SQL Server Database Engine
Comments
Post a Comment