Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Can this happen?

$
0
0

Env : SQL Server 2008 R2

This is my SP

BEGIN TRANSACTION;

BEGIN TRY
    Delete...from my table(say TABLE1)

    If all records has been deleted from TABLE1

       Begin

             Insert......TABLE1

       End

    IF @@TRANCOUNT > 0
        COMMIT TRANSACTION;
END TRY
BEGIN CATCH
    ....

    IF @@TRANCOUNT > 0
        ROLLBACK TRANSACTION;
END CATCH;

Let's say there are two threads, A and B...

A thread ran this sp..then..when B thread about to run this same sp, if the A thread was still running(before commit/or rollback), the B thread should wait until the the transaction of A thread is done...

Since the A thread was holding that transaction until the commit/or rollback, B thread shouldn't be able to interleave...

Is my understanding correct?

However, the thing that I found..sometimes I noticed that I have duplicated records in TABLE1 that looks like for whatever reason, didn't work that way I was thinking ...

Any idea?

Thanks,


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>