Using TABLOCK

Oct 4, 2007

Hi all,

During a load test , we found a procedure that was causing a deadlock. In the profiler deadlock graph both the process that blocked as well as the victim where having the same object id of the procedure.

I used WITH (TABLOCK) hint and now I'm not finding the deadlocks.

Is this a right solution ?
Will this affect the functionality ?

Code piece inside the procedure when it caused deadlocks

INSERT INTO Table1
SELECT @Col1, @Col2, @Col3, @Col4

UPDATE Table1
SET Col5 = @Col5
WHERE @Col1 = @Var

UPDATE Table2
SET Col = @ColVal

Code piece changed now with WITH (TABLOCK)

INSERT INTO Table1
SELECT @Col1, @Col2, @Col3, @Col4

UPDATE Table1 WITH (TABLOCK)
SET Col5 = @Col5
WHERE @Col1 = @Var

UPDATE Table2 WITH (TABLOCK)
SET Col = @ColVal


Any suggestions would be appreciated.

Thanks,

DBLearner

View 3 Replies


ADVERTISEMENT

Transact SQL :: Table Locking With TABLOCK

Oct 20, 2015

We currently have a large ETL import each night. There are lots of tables and some are quite large. If there is a problem with the nightly import, it is rerun during the day while users are running reports. The only updates to the tables is the nightly import.Currently the import does a BULK Insert and several INSERT INTOs. We are going to try to improve performance by adding a WITH (TABLOCK). But wonder if the TABLOCK will cause more locking, less locking, or be about the same. We do not have transactions batched. We insert all the records for a table in a single transaction. 

Have found these references regarding TABLOCK, but I am confused what they mean, and how they differ from doing a BULK INSERT or INSERT INTO without TABLOCK.

TABLOCK - Specifies that a shared lock is taken on the table held until the end-of-statement. [URL] ....
Using INSERT INTO…SELECT to Bulk Load Data with Minimal Logging [URL] ....
Lock Modes [URL] ....

View 7 Replies View Related

SQL Server 2014 :: Why Don't Bulk Imports TABLOCK By Default

Jul 2, 2014

I've been reading about the "table lock on bulk load" option and TABLOCK hint.

So my understanding is by default only row locks are taken out and other queries can read/write data while the bulk load is going on. However if you were doing parallel bulk loads with overlapping keys from a clustered index then they may block each other.

But if the option is enabled, you can do the parallel bulk loads without blocking because a table lock is taken out, however, other processes couldn't read/write the data until they're all done.

Is that the gist of it? I think I got confused by some misinformation. Don't all those row locks eventually likely escalate to a table lock anyway though?

View 1 Replies View Related

DEADLOCKs While BCPin Using &"TABLOCK&" Hint

Apr 21, 2008

Hi,

*** Skip all and go to last 2nd para for main question ****

We have our custom ETL tool that loads data in SS 2005 Enterprise Vesion using BCP. We use '-h "TABLOCK"' table hint and '-b 10000' batch size options.

Prior to 2005 Enterprise version (2K and 2K5 Standard Versions), we use to maintain around 10 DBs with same schema/sps and views in each of the dbs.

Now, in Enterprise version we are maintaining one DB where all tables are partitioned by one column.

Multiple instances might run from different workstations. Here, I want to clarify you that no instance will load data pertaining to another partition.

But at the same time there will be other components running that will query the tables in a SELECT sql and all tables have NOLOCK table hint.

There can be multiple instances of this component running from different workstations. Again, none of the instance will not access data pertaining to another instance (including the component that is loading data)

I have no clue why we some times get deadlock issues when we run multiple instances of custom ETL tool for loading data and other component that just has select only sql.

More over I get deadlocks many times only in BCP, this is a puzzle to me because i use NOLOCK table hint. This is the only place where table is populated by data and data in table neither updates or deleted.

Can some one tell which of these below concurrent transactions will get conflicts and leads to dead lock?


bcping data into table of partition A
bcping data into table of partition B
deleting few rows of data from table of partition E
updating few rows of data from table of partition F
querying table of partition C
querying table of partition D


Thanks
- D

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved