By default, SQL Server works in AUTOCOMMIT mode so COMMIT is issued after each statement, but when a explicit transaction is started, SQL Server does not issue a COMMIT after a DDL statement:
Let's start a transaction, create a table in SQL Server and insert a row:
SQL Server:
-- Start a transaction explicitly
BEGIN TRANSACTION;
-- Create a table and insert a row
CREATE TABLE states
(
abbr CHAR(2),
name VARCHAR(90)
);
INSERT INTO states VALUES ('CA', 'California');
-- 1 row(s) affected
Now let's create another table, insert a row and perform ROLLBACK operation:
SQL Server:
-- Create another table table and insert a row
CREATE TABLE cities
(
name VARCHAR(90),
state CHAR(2)
);
INSERT INTO cities VALUES ('San Francisco', 'CA');
-- 1 row(s) affected
ROLLBACK;
You can see that after ROLLBACK, none of the tables exists:
SQL Server:
SELECT COUNT(*) FROM states;
-- Msg 208, Level 16, State 1, Line 1
-- Invalid object name 'states'.
SELECT COUNT(*) FROM cities;
-- Msg 208, Level 16, State 1, Line 1
-- Invalid object name 'cities'.