I have one warehouse server which got data/sync from legacy system 24/7, I noticed some of my reports/sql jobs performance is uncertain and most of the time I heard from DBA team that my query is blocking to other sync process.
From DBA team I came to know command i.e. EXEC SP_WHO2 by which I can identify spid of query which cause blocking by looking into column BlkBy.
Please suggest me how I can avoid blocking and other ways to check blocking in SQL Server
This is a very comprehensive guide. Some basic guidelines though:
SELECT ... INTO #temp
pattern and instead create a table first and useINSERT INTO #Temp SELECT...
WITH (NOLOCK)
on queries where you can tolerate dirty readsWHERE
clausesREAD_COMMITTED_SNAPSHOT
isolation levelApart from Sp_Who2 you can use following query to identify blocking in you SQL.
Also can check detail of particular SPID by using following command.
There is an another query which can be useful. This query will provide you important details about blocking session id,time(from when the blocking session is running),executing query,user account who is executing this blocking session. The query is very useful when you are dealing with a production environment with many users running their transactions and you are supposed to find out blocking session and user and take necessary action.