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 6215669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:05:55+00:00 2026-05-24T07:05:55+00:00

In Sql Server 2008 r2, I have a table called Emp, and I’m trying

  • 0

In Sql Server 2008 r2, I have a table called Emp, and I’m trying to update some values in a transaction (outer tran), now after the update and before the commit, I began another transaction, in witch i tried to select data from the same table (Emp) but via a loopback linked server.
the tsql look like this:

USE MASTER

GO

EXEC sp_addlinkedserver @server = N'loopback',@srvproduct=N'',@provider = N'SQLNCLI', @datasrc = @@SERVERNAME,@catalog = 'MstrDtl'
GO

EXEC sp_serveroption loopback,N'remote proc transaction promotion','FALSE'

Go

create SYNONYM loopy FOR loopback.MstrDtl.dbo.Emp


use MstrDtl
BEGIN TRAN OuterTran
      BEGIN
      update table dbo.Emp set Salary = 123456 where Name='abcdx'
            BEGIN TRAN InnerTran
                  select Salary from loopy where Name = 'abcdx'
            COMMIT TRAN InnerTran
            ROLLBACK TRAN OuterTran
      END

so i have two questions:

  • can i get old values (the affected rows with the update) in the query to loopback inside the InnerTran using this way?
  • the query never stops, any idea?
  • 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-24T07:05:57+00:00Added an answer on May 24, 2026 at 7:05 am

    To answer your questions:

    1. No, you cannot get the old values in that way; you’ll get blocked (see #2) or you’ll get the new values.

    2. The reason the query never stops is because you’re blocking yourself (technically, you’re deadlocking yourself.) Your outer transaction is holding a lock on that row (page actually) and therefore the loopback query is blocked until the update lock is released. You could (but shouldn’t) specify WITH (NOLOCK) on your loopback query but that will actually return the updated but uncommitted row.

    If you want the OLD values in your query use the OUTPUT clause. http://msdn.microsoft.com/en-us/library/ms177564.aspx

    CREATE TABLE #emp
    (
        id INT IDENTITY PRIMARY KEY CLUSTERED,
        empName VARCHAR(255),
        salary MONEY
    )
    go
    
    INSERT INTO #emp(empName, salary) 
    SELECT 'bill', 5000
    UNION ALL 
    SELECT 'ted', 5000
    UNION ALL 
    SELECT 'cheech', 35000
    UNION ALL 
    SELECT 'chong', 15000
    UNION ALL 
    SELECT 'tango', 70000
    UNION ALL 
    SELECT 'Cash', 200000
    
    GO
    
    DECLARE @oldValues TABLE
    (
        id INT,
        empname VARCHAR(255),
        salary money
    )
    
    
    UPDATE #emp SET salary = salary + 500
    OUTPUT DELETED.* INTO @oldValues
    WHERE  empName = 'bill'
    
    SELECT E.empName, E.salary AS NewSalary, O.salary AS OldSalary
    FROM #emp E
        INNER JOIN @oldValues O 
            ON E.id = O.id 
    
    DROP TABLE #emp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have SQL Server 2008 with a table called ProductCategories designed like this: Id
In our inventory database (SQL Server 2008 std edition) we have a table (called
We are using SQL Server 2008. We have a table called response which has
Greeting all. I have a SQL Server 2008 Express database with a table called
I have SQL Server 2008 database with two tables. The first table is called
I have a table in MS SQL Server 2008 with a varchar column called
I have a SQL Server 2008 database. This database has a Table called Book.
I have a SQL Server 2008 database. There is a table called Documents with
I have a table called XML (in SQL Server 2008) and it has a
I have a SQL Server 2008 database. This database has a table called Product,

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.