Minimizing Blocking Conditions

One problem that you can run into when you insert data into a table is blocking due to large amounts of locks. Locks are used to keep multiple users from changing the same data at the same time. For more information on locks, see Chapter 16, "Consideration When Using Stored Procedures and Triggers." A block occurs when one user holds a lock on a resource and other users require that resource. This results in one user being placed in a wait state, or being blocked, until the other user releases the lock. If the lock is being held on a table and the query is long running, this can result in huge amounts of time that users have to wait.

You can minimize locking conditions in several ways. First, use good judgment ...

Get Writing Stored Procedures for Microsoft SQL Server now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.