Answered by:
What does BEGIN TRAN and ROLLBACK do in a query window?

Question
-
I installed SSMS ToolPack and now in every query I have it would show
BEGIN TRAN
ROLLBACK
What does these do? Like If I run a select query within them, it runs fine, I didn't try to do anything else. I read online about this a while ago and I remember that you have to set a TRAN for begin part, but I don't know what is the use for these as they are right now. Any help would be appreciated
Friday, November 12, 2010 9:09 PM
Answers
-
See MSDN:
BEGIN TRANSACTION (Transact-SQL)
COMMIT TRANSACTION
ROLLBACK TRANSACTIONIf you are doing some data change (UPDATE / INSERT), you can commit the changes or, if some problem/errors occur, you can rollback these changes to "undo" them.
Olaf Helper ----------- * cogito ergo sum * errare humanum est * quote erat demonstrandum * Wenn ich denke, ist das ein Fehler und das beweise ich täglich http://olafhelper.over-blog.de- Proposed as answer by Chirag Shah Friday, November 12, 2010 10:35 PM
- Marked as answer by Tom Li - MSFT Wednesday, November 24, 2010 2:39 AM
Friday, November 12, 2010 9:19 PM -
These lines start a transaction and rollback it, it means what if you run an update or insert or delete command, it will not be committed. It's sort of prevention of an error.
I removed these lines in my SSMS installation.
For SELECT statement these lines don't do anything.
Premature optimization is the root of all evil in programming. (c) by Donald Knuth
Naomi Nosonovsky, Sr. Programmer-Analyst
My blog- Proposed as answer by Chirag Shah Friday, November 12, 2010 10:35 PM
- Marked as answer by Tom Li - MSFT Wednesday, November 24, 2010 2:39 AM
Friday, November 12, 2010 9:24 PM
All replies
-
See MSDN:
BEGIN TRANSACTION (Transact-SQL)
COMMIT TRANSACTION
ROLLBACK TRANSACTIONIf you are doing some data change (UPDATE / INSERT), you can commit the changes or, if some problem/errors occur, you can rollback these changes to "undo" them.
Olaf Helper ----------- * cogito ergo sum * errare humanum est * quote erat demonstrandum * Wenn ich denke, ist das ein Fehler und das beweise ich täglich http://olafhelper.over-blog.de- Proposed as answer by Chirag Shah Friday, November 12, 2010 10:35 PM
- Marked as answer by Tom Li - MSFT Wednesday, November 24, 2010 2:39 AM
Friday, November 12, 2010 9:19 PM -
These lines start a transaction and rollback it, it means what if you run an update or insert or delete command, it will not be committed. It's sort of prevention of an error.
I removed these lines in my SSMS installation.
For SELECT statement these lines don't do anything.
Premature optimization is the root of all evil in programming. (c) by Donald Knuth
Naomi Nosonovsky, Sr. Programmer-Analyst
My blog- Proposed as answer by Chirag Shah Friday, November 12, 2010 10:35 PM
- Marked as answer by Tom Li - MSFT Wednesday, November 24, 2010 2:39 AM
Friday, November 12, 2010 9:24 PM