title: How to avoid Table Locks while Inserting Data in table
body: <p>In our application we are inserting records in 15 tables in a transaction from C# code.
  For this we are creating one insert statement for each table, and append all in one query and use 'ExecuteNonQuery' to insert records in table. Because, we want insert to happen in all table and don't want any inconsistent data, we are using it in a transaction. </p>
  
  <p>This functionality is written in a service and more than once service (same services, different installations) perform this task (inserting data into tables) concurrently.
  These services are inserting totally different rows in tables and not in any way dependent.</p>
  
  <p>But, when we are running these services we are getting deadlocks on these insert statements.</p>
  
  <p>The code is like this:</p>
  
  <ol>
  <li>Open DB Connection</li>
  <li>Begin Transaction</li>
  <li>Insert data in tables</li>
  <li>Commit Transaction.</li>
  </ol>
  
  <p>All services perform these steps on different set of data going in same 15 tables.</p>
  
  <p>SQL Profiler trace suggests there are exclusive locks on these tables while insert.</p>
  
  <p>Can you please suggest why it should be having table level locks while just firing insert statement on table and ending in deadlocks. And what is the best possible way to prevent it.</p>