Search code examples
locking

Critical section in query SQL Server stored procedure


I have a stored procedure and I want to run it once at the same time.

In the other hand Like lock variable in C# programing.

Can anyone help me?


Solution

  • for this situation you can use 2 solution for your critical section and the block you want to only one time a time

    First use SET TRANSACTION ISOLATION LEVEL SERIALIZABLE

    For example

    SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
    begin Tran
    your Query
    Commit Tran
    

    Second Use DeadLock priority normal

    SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
        begin Tran
        your Query
        Commit Tran