I am working on pymssql, a python MSSQL driver. I have encountered an interesting situation that I can't seem to find documentation for. It seems that when a CREATE TABLE statement fails, the transaction it was run in is implicitly rolled back:
-- shows 0 select @@TRANCOUNT BEGIN TRAN -- will cause an error INSERT INTO foobar values ('baz') -- shows 1 as expected select @@TRANCOUNT -- will cause an error CREATE TABLE badschema.t1 ( test1 CHAR(5) NOT NULL ) -- shows 0, this is not expected select @@TRANCOUNT I would like to understand why this is happening and know if there are docs that describe the situation. I am going to code around this behavior in the driver, but I want to make sure that I do so for any other error types that implicitly rollback a transaction.
NOTE
I am not concerned here with typical transactional behavior. I specifically want to know why an implicit rollback is given in the case of the failed CREATE statement but not with the INSERT statement.