tsql - Conflict between UPDATE and SELECT -


i have table db.data_feed update using t/sql procedure. every minute, procedure below executed 100 times different data.

alter procedure [db].[update_data_feed]      @p_market_date varchar(max),    @p_curr1 int,    @p_curr2 int,    @p_period float(53),    @p_mid float(53)      begin        begin try           update db.data_feed             set                 mid = @p_mid,                 market_date = convert(datetime,@p_market_date, 103)                             cast(market_date date) =                 cast(convert(datetime,@p_market_date, 103) date) ,              curr1 = @p_curr1 ,              curr2 = @p_curr2 ,              period = @p_period           if @@trancount > 0             commit work         end try        begin catch           --error code        end catch     end   end 

when users use application, read table, per sql below. potentially select can run thousands of times in 1 minute. (questions marks replaced parser appropriate date/numbers)

declare @mydate date; set @mydate='?' select * db.data_feed market_date>=@mydate , market_date<dateadd(d,1,@mydate) , curr1 = ? , curr2 = ? , period = ?  order period 

i have sometimes, albeit rarely, got database lock.

using the script http://sqlserverplanet.com/troubleshooting/blocking-processes-lead-blocker saw spid=58. did declare @spid int; set @spid = 58; dbcc inputbuffer(@spid) find sql script turned out select statement.

is there wrong sql code? can prevent such locks happening in future?

thanks

readers have priority on writers when writing readers have wait writing finish. there 2 table hints ca try 1 nolock reads uncommited lines (dirty reads) , other readpast (only reads information has been commited on last commit). in both cases readers never block table, there not deadlock writer.

writers can block other writers but, if understood correctly, 1 write per execution readers intercalate writes, diminuishing deadlocks.

hope helps.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -