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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:39:12+00:00 2026-06-10T03:39:12+00:00

I have a bunch of data which will insert into a table. This issue

  • 0

I have a bunch of data which will insert into a table. This issue is that I need it to return the primary key to that table. I wasn’t sure if there was things like:

 insert into TABLE (...) values (...) RETURNING p_key

or

 select p_key from (insert into TABLE (...) values (...))

I am making a workaround for a browser and saved information which will more or less add a row and then update it… but without the primary key, there is no way to update it as there is no reference to it.

I was looking online and found some examples via google, but it confused me slightly with these examples.

http://en.wikipedia.org/wiki/Insert_(SQL)#Retrieving_the_key

http://www.daniweb.com/web-development/databases/ms-sql/threads/299356/returning-identity-of-last-inserted-row-uniqueidentifier

Wikipedia was saying that for SQL Server 2008 to use OUTPUT instead of RETURNING, possible to use something like OUTPUT p_key

  • 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-10T03:39:13+00:00Added an answer on June 10, 2026 at 3:39 am

    If you’re inserting a whole set of rows, selecting the SCOPE_IDENTITY() won’t do. And SCOPE_IDENTITY also only works for (numeric) identity columns – sometimes your PK is something else…

    But SQL Server does have the OUTPUT clause – and it’s very well documented on MSDN!

    INSERT INTO dbo.Table(columns)
    OUTPUT INSERTED.p_key, INSERTED.someothercolumnhere .......
    VALUES(...) 
    

    Those values will be “echoed” back to the calling app, e.g. you’ll see them in a grid in SQL Server Management Studio, or you can read them as a result set from your C# or VB.NET calling this INSERT statement.

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

Sidebar

Related Questions

I have to copy a bunch of data from one database table into another.
I have a php array that has a bunch of data that I need
So this is the scenario: You have a bunch of data that needs to
I have an Oracle table with data that looks like this: ID BATCH STATUS
Say that I have a table with a bunch of records, which I want
I have an SQL Azure database with a table that has JobId primary key.
I have a django view generating a bunch of data which I want to
So in my app I have a bunch of data that I'd like to
I have a bunch of overloaded functions that operate on certain data types such
I have an app that has a bunch of Core Data that it needs

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.