SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Why is this happening
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

62 Posts

Posted - 07/19/2013 :  15:07:38  Show Profile  Reply with Quote



What does the above command do? Every time I click on new New Query button in SQL Server Managment, those two lines are already there.

James K
Flowing Fount of Yak Knowledge

3865 Posts

Posted - 07/19/2013 :  15:19:43  Show Profile  Reply with Quote
It is simply creating a stub for you. You would write your code in between the two statements. Then, when you run the code, it will open a transaction (the BEGIN TRAN statement), run the code that you wrote, and then roll it back (i.e., undo all the operations you did). This way you can test your code without impacting the database. When you are happy with what you have done, you would change the ROLLBACK to COMMIT. That then would cause your changes to be "committed" i.e., persisted.

If you are doing changes to a production database, this helps preview your changes to make sure that what you are doing affects only the rows that should be affected etc. If you are in a production environment, be careful about opening a transaction, making updates to data in tables and leaving that transaction open. You want to commit or rollback as soon as possible - otherwise, other clients who are trying to access those tables/rows would not be able to and so can cause the production queries to fail.
Go to Top of Page

Almighty SQL Goddess

38114 Posts

Posted - 07/19/2013 :  15:53:27  Show Profile  Visit tkizer's Homepage  Reply with Quote
You are probably using Mladen's SSMS Tools Pack. I disable that option.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server

Subscribe to my blog
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000