How to Stop a query from Auto Committing in Microsoft SQL Server Management Studio.

By default Microsoft SQL Server Management Studio Query (Query Analyzer) auto commits leaving no option to rollback.  I had been very use to this and preferred it this way, however, recently I had been working in an environment with different tools where explicit commit was the preferred way and so now I want the flexibility of both in SQL Server as well.

One option is to turn on implicit transactions at the beginning of your query using  “set implicit_transactions on”.  When this is on, you will still see all of the updated or inserted row counts when executing your query, but you will have the option to rollback or commit.

Another way is to turn on implicit transactions by default within SQL Server Management Studio.

  1. Tools –> Options
  2. Expand Query Execution –> SQL Server
  3. Select ANSI
  4. Either Check SET IMPLICIT_TRANSACTIONS or SET ANSI_DEFAULTS

JUST BECAREFUL.  Don’t leave a transaction open because it may end up blocking other users.  Always make sure to commit or rollback.

MSDN Ref – http://msdn.microsoft.com/en-us/library/ms187807.aspx

Explore posts in the same categories: SQL Server

Tags:

You can comment below, or link to this permanent URL from your own site.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: