title: Alternate synonym in SQL Server in one transaction
body: <p>I am new to Transact SQL programming.</p>
  
  <p>I have created a stored procedure that would drop and create an existing synonym so that it will point to another table. The stored procedure takes in 2 parameters:</p>
  
  <ul>
  <li>synonymName - an existing synonym</li>
  <li>nextTable - the table to be point at </li>
  </ul>
  
  <p>This is the code snippet:</p>
  
  <pre><code>...
  BEGIN TRAN SwitchTran
     SET @SqlCommand='drop synonym ' + @synonymName
     EXEC sp_executesql @SqlCommand
     SET @SqlCommand='create synonym ' + @synonymName + ' for ' + @nextTable
     EXEC sp_executesql @SqlCommand
  COMMIT SwitchTran
  ...
  </code></pre>
  
  <p>We have an application that would write data using the synonym regularly.</p>
  
  <p>My question is would I run into a race condition where the synonym is dropped, while the application try to write to the synonym?</p>
  
  <p>If the above is a problem, could someone give me suggestion to the solution.</p>
  
  <p>Thanks </p>