Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
ugh3012
Yak Posting Veteran
62 Posts |
Posted - 2013-07-19 : 15:07:38
|
[code]BEGIN TRANROLLBACK[/code]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
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-07-19 : 15:19:43
|
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. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|