SQL Server: Does 'DROP TABLE' inside transaction causes an implicit commit?

Mauro Bilotti picture Mauro Bilotti · Jul 18, 2014 · Viewed 17.4k times · Source

My question is kind of easy but i'm still doubting after I created this transaction. If I execute the following code:

BEGIN TRANSACTION
      DROP TABLE Table_Name

Can I perform a ROLLBACK TRANSACTION that recovers the dropped table? I'm asking because I don't know what happens in the 'Object Explorer' and I didn't found any question of this topic, so I think that it could be a useful issue.

Answer

Sean Lange picture Sean Lange · Jul 18, 2014

This is incredibly easy to test.

create table TransactionTest
(
    ID int identity primary key clustered,
    SomeValue varchar(20)
)

insert TransactionTest
select 'Here is a row'

begin transaction
    drop table TransactionTest
rollback transaction

select * from TransactionTest