Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6990453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:21:08+00:00 2026-05-27T19:21:08+00:00

This: use test; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; BEGIN TRANSACTION; EXEC sp_RENAME ‘table1.asd’

  • 0

This:

use test;

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;


BEGIN TRANSACTION;

EXEC sp_RENAME 'table1.asd' , 'ads', 'COLUMN';

INSERT INTO table1 (ads) VALUES (12);

COMMIT

is a simple example that demonstrates what I would like to do.

I want to alter the table in some way and perform inserts/deletes in one transaction (or other modifications to the table).

The problem is that the results from sp_RENAME are never immediately visible to the INSERT statement. I’ve played with different transaction isolation levels – it’s always the same (therefore the transaction never commits).

Normally I would just use GO statements for this to be in separate batches, but I need that in one batch, because…

My real task is to write a script that adds identity and FK to a table (this requires creating another table with the new schema, performing identity inserts from the old one, renaming the table and applying constraints). I need to play it safe – if any part of the procedure fails I have to rollback the whole transaction. This is why I wanted to do something like this:

BEGIN TRAN
    --some statement

    IF (@@ERROR <> 0) GOTO ERR_HANDLER

    -- some other statement

    IF (@@ERROR <> 0) GOTO ERR_HANDLER

COMMIT TRAN

RETURN 0

ERR_HANDLER:
PRINT 'Unexpected error occurred!'
ROLLBACK TRAN
RETURN 1

Since labels work only inside a batch I cannot use GO statements.

So how can I:

  • make statements(ie. ALTER TABLE, sp_RENAME) have an immediate effect ?

or

  • write the whole solution some other way so that it is safe to run in production DB ?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:21:09+00:00Added an answer on May 27, 2026 at 7:21 pm

    The issue is that the parsing of the batch fails when it encounters the reference to the renamed column so the entire batch never gets executed – not that the effects of the transaction are not visible.

    You can put your statements referencing the new name of the column in an EXEC('') block to defer compilation until after the column is renamed.

    EXEC sp_rename 'table1.asd' , 'ads', 'COLUMN';
    EXEC('INSERT INTO table1 (ads) VALUES (12);')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this SP USE [Test] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON
<?php $language = $_SERVER['HTTP_ACCEPT_LANGUAGE']; echo $language; ?> When I use Firefox to test this
I'm puzzled with this test script: #!perl use strict; use warnings; use encoding 'utf8';
I have a string of test like this: <customtag>hey</customtag> I want to use a
I have this use case of an xml file with input like Input: <abc
When I run this: use feature ':5.10'; $x=1; given ($x) { when(1) { say
So I've looked at this use of the freebase API and I was really
I am doing pass-by-reference like this: use strict; use warnings; sub repl { local
I would like to change this: // use appropiate lang.xx.php file according to the
I use the Action<object>.BeginInvoke() method, does this use the thread pool or not? I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.