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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:37:07+00:00 2026-06-16T20:37:07+00:00

This question has been asked before…but I can’t seem to find the exact answer

  • 0

This question has been asked before…but I can’t seem to find the exact answer I’m looking for… I need to insert a bunch of records and get back the inserted identity values… I’m doing this:

INSERT MyTable(col1, ....)
OUTPUT inserted.IdentityColumn
SELECT p.i.value('@XmlAttribute', 'nvarchar(128)') FROM @myXml.nodes('/root/i') AS p(i)

This works fine…

Enter SQL transactional replication with updatable subscriptions, which places triggers on replicated tables on subscribers.

OUTPUT no longer works in this scenario…

So, I’m doing this now…but I have a bad feeling in my gut about this and I think I’ve opened the door to a concurrency issue (though I’m not positive).

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE  
DECLARE @currentIdentity bigint
SET @currentIdentity = SELECT IDENT_CURRENT('MyTable') + 1
...
SELECT IdentityColumn FROM MyTable WHERE IdentityColumn <= IDENT_CURRENT('MyTable') AND IdentityColumn >= @currentIdentity

Suggestions? This also stinks because the approach doesn’t work for generated uniqueidentifiers.

  • 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-06-16T20:37:08+00:00Added an answer on June 16, 2026 at 8:37 pm

    You can use the variant of OUTPUT that inserts into a table variable. From the documentation:

    If the OUTPUT clause is specified without also specifying the INTO keyword, the target of the DML operation cannot have any enabled trigger defined on it for the given DML action. For example, if the OUTPUT clause is defined in an UPDATE statement, the target table cannot have any enabled UPDATE triggers.

    (Emphasis added)

    So, you can have:

    DECLARE @IDs table (ID int not null)
    INSERT MyTable(col1, ....)
    OUTPUT inserted.IdentityColumn INTO @IDs
    SELECT p.i.value('@XmlAttribute', 'nvarchar(128)') FROM @myXml.nodes('/root/i') AS p(i)
    
    SELECT * from @IDs
    

    Which will have approximately the same behaviour as the original, unless you’re processing e.g. row count messages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm sorry if this question has been asked before, but I can't seem to
This question has been asked before, but I can't find any answers that have
This question has been asked before perhaps multiple times, but I can't get the
I feel like this question has been asked before but the answers seem pretty
I know this question has been asked before, but I tried eveything and can't
I realize this question has been asked before, but I can't get it to
I know this question has been asked before, but I wasn't able to find
I'm sure this question has been asked before, but I'm too frustrated to find
This question has been asked before, but the answered ones I could find were
This question has been asked before, but not with this exact issue. I have

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.