I am new to Transact SQL programming.
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:
- synonymName - an existing synonym
- nextTable - the table to be point at
This is the code snippet:
...
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
...
We have an application that would write data using the synonym regularly.
My question is would I run into a race condition where the synonym is dropped, while the application try to write to the synonym?
If the above is a problem, could someone give me suggestion to the solution.
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…