Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Administration - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 6525

Deadlock issue

$
0
0
Hi friends,I wish a good weekend for all :)I have a problem with a deadlock.Deadlock graph[IMG]http://i58.tinypic.com/b5k3mv.png[/IMG][b]The first query is :[/b]Update Booking_Basket set Cancelled=N'N',Departure=N'AYT',Arrival=N'a235c451900c428a8fc92f310be59364',CancelDate=N'19000101 00:00:00',CheckInDate=N'20150618 00:00:00',CheckOutDate=N'20150618 23:59:59',Class=N'',MealType=N'',ProductName=N'Group Transfer',CommissionRatio=0.1,CommissionBase=1985.46756,CommissionAmount=198.54,RemoteSysRef=N'',SupplierSalePrice=25,SupplierReducedPrice=0,SupplierSaleCurr=N'USD',DmcSalePrice=25,DmcSaleCurr=N'USD',OprSalePrice=30,OprSaleCurr=N'USD',OprSaleCrossRate=56.8088,OprSaleSurcharge=0[b] Where ID=669125 [/b] [b]There is a trigger on this table which updates [u]Booking_Main[/u] table.[/b]ALTER TRIGGER [dbo].[trgInsUpdBookingBasket] ON [dbo].[Booking_Basket] AFTER INSERT,UPDATEAS BEGIN SET NOCOUNT ON; declare @BkgNumber varchar(16); declare cs cursor LOCAL STATIC READ_ONLY FORWARD_ONLY for select Distinct BkgNumber from inserted; open cs; fetch cs into @BkgNumber; while(@@FETCH_STATUS=0) begin update [b]Booking_Main[/b] Set DateBegin = (select min(CheckInDate) from Booking_Basket where BkgNumber=@BkgNumber and Cancelled='N'), DateEnd = (select max(CheckOutDate) from Booking_Basket where BkgNumber=@BkgNumber and Cancelled='N') [b]where ID=@BkgNumber;[/b] fetch cs into @BkgNumber; end; close cs deallocate csEND[b]The deadlock victim process[/b]Update [b]Booking_Main[/b] set ServicesTotal=34132.928941419,TourPrice=39765,TotalCommission=3977,FuelSurcharges=6600,AgencyShouldPay=42388,Balance=-27388,BkgGuid=N'3e3a51ed403344d28f4834c59680564b',Status=N'WOC' Where [b]ID=N'104324976' [/b][b]So there are two updates which deadlock.[/b]I have all the nonclustered indexes for where clauses for [b]Booking_Main[/b] and everything works with Index Seek.I have suggested not using the cursor for the programmer. But, surely he will continue use it :DI don't know what to do more.Here is the execution plan. [IMG]http://i60.tinypic.com/2uj04dz.png[/IMG]Thanks for your helpMurat

Viewing all articles
Browse latest Browse all 6525

Trending Articles