I used the following code:
--begin tran redist1
/*--FIRST Update
update db..tablename set column=value
where complexthing = othercomplexthing
*/
/*--SECOND Update
update db..tablename set column=replace(column,'A','1')
*/
select * from db..tablename
--rollback tran redist1
--commit tran redist1
I highlighted “begin tran redist1”, ran it, highlighted the FIRST update statement and ran it, then did the same with the select statement. It worked, so I highlighted “commit tran redist1”.
Next I highlighted “begin tran redist1”, ran it, highlighted the SECOND update statement and ran it, then did the same with the select statement. It did not work, so I highlighted “rollback tran redist1”.
Next I highlighted “begin tran redist1”, ran it, highlighted the SECOND update statement and ran it, then did the same with the select statement. It worked this time, so I highlighted “commit tran redist1”.
I used several more update statements, repeating this process each time. I then opened an “edit” window to change values directly after my last “commit”, but SQL server kept timing out for that window alone, saying my “commit tran redist1” was the blocking transaction, despite having completed. I ran the commit again, and the edit window opened, showing the data as I had changed it.
This morning, I opened up the edit window again, and the table was somehow back to just after I ran the FIRST query + commit. All later queries + commits were lost. The record I edited manually in the edit window was still edited, however.
Note that each time, I used the name “redist1”, ending with a commit or a rollback as appropriate for each transaction. My question is, was the reuse of the name the cause of my problem? Does the reuse of the name create a conflict of some type?
BEGIN TRANdoesn’t require any name – the name is optional.Transactions, however, can be nested and if you did not complete the first one, it will still be in effect even after the others have completed – if you roll it back, they will all roll back.
What probably happened is that you did not commit a transaction, so the following transactions were nested. When the transaction rolled back (possibly due to a timeout), they all rolled back.