Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

SQLStudies

My name is Kenneth Fisher and I am Senior DBA for a large (multi-national) insurance company. I have been working with databases for over 20 years starting with Clarion and Foxpro. I’ve been working with SQL Server for 12 years but have only really started “studying” the subject for the last 3. I don’t have any real "specialities" but I enjoy trouble shooting and teaching. Thus far I’ve earned by MCITP Database Administrator 2008, MCTS Database Administrator 2005, and MCTS Database Developer 2008. I’m currently studying for my MCITP Database Developer 2008 and should start in on the 2012 exams next year. My blog is at www.sqlstudies.com.

Transactions: What commands aren’t allowed?

Transactions are great tools that every DBA and developer should learn how to use. Unfortunately not everything can be put inside a transaction. There are a handful of commands that won’t work inside a transaction. CREATE, ALTER and DROP DATABASE for example. The full list of commands can be found here.

When you try to run one of these commands inside a transaction you will get the following error.

BEGIN TRANSACTION
CREATE DATABASE NoTransaction
COMMIT

Msg 3902, Level 16, State 1, Line 1
The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.

I suspect that anything that affects the file system is not going to work in a transaction. Xp_cmdshell for example is not on the list and doesn’t given an error but the results aren’t rolled back.

BEGIN TRANSACTION
EXEC xp_cmdshell 'dir c:\ > c:\temp\dir.txt'
ROLLBACK
EXEC xp_cmdshell 'dir c:\temp\dir.txt'

You will note that dir.txt exists even though the transaction was rolled back. It’s fairly obvious, but still something that should be kept in mind. According to the link above UPDATE STATISTICS is another one of those things that will not throw an error but still doesn’t get rolled back.

Transactions are a big subject which I’m going to explore over several posts. I am by no means going to cover the subject exhaustively but if you have any subjects you would like me to cover or think I’ve missed something feel free to comment or email me.


Filed under: Microsoft SQL Server, SQLServerPedia Syndication, T-SQL, Transactions Tagged: code language, language sql, microsoft sql server, T-SQL, transactions

Comments

Leave a comment on the original post [sqlstudies.com, opens in a new window]

Loading comments...