views:

6

answers:

1

I'm developing an ETL application with batch processing. There is low (i.e. no) concurrency for updates. I'd like to avoid the overhead of granular locks and lock escalation by merely locking the entire table.

I'd like to avoid having to specify TABLOCK in every statement. Is there any way to set the locking granularity at the top of a stored procedure such that every statement automatically gets table locks on every table used? Shared or exclusive doesn't matter, though shared is preferred; the ETL will run overnight with no adhoc query load and prior to a batch of reports triggered when the ETL is complete.

Thanks!

A: 

You will need to take a look at Transaction Isolation Levels

To be honest though, I can't see why you need to be doing anything. I would have thought SQL Server would do a good enough job of locking by itself.

Barry
I was afraid there's no option. Isolation level doesn't directly affect granularity, though if I use serializable it will use range-locks, but there's no way to tell how granular those ranges are. I'm trying to optimize beyond "good enough". To me, it's worth putting a SET statement in a stored procedure, but not putting table hints on every statement.
entaroadun