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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:29:12+00:00 2026-06-16T11:29:12+00:00

Possible Duplicate: Best way to get identity of inserted row? So lets imagine I

  • 0

Possible Duplicate:
Best way to get identity of inserted row?

So lets imagine I am building an Auction database for the first time using SQL Server 2012.

Someone creates an auction listing and this is inserted into the database and given a new unique AuctionID. Along with the insertion of the auction, there are many other pieces of data that need to be stored and associated with the auction e.g. images, product properties, etc.

There is a table that holds basic Auction data, and then other tables to store all the other pieces of information that allow for a many-to-many relationship with the Auction.

Now then, in the other tables that hold data about the Auction there would at least be one column that contains the AuctionID and one other column that holds some other info e.g. product specifications.

My way of achieving this (so far) is to first do the insertion of the basic Auction listing and let the database give it a new AuctionID. Fantastic. Next I do this:

SELECT TOP 1 AuctionID FROM Auction
ORDER BY Timestamp DESC

This should return the AuctionID that was last inserted, and if run immediately after the insertion should be the correct one.

I then take this AuctionID, and use that value when inserting the additional information pieces into the other table therefore creating a many-to-many relationship. Viola!

However, is this the correct way to do this when there are millions of transactions happening at the same time so theoretically insertions might be happening within millisecods of each other. Between an insertion taking place, and me retreiving the last inserted AuctionID, I could end up with the wrong AuctionID.

Can anyone please be kind enough to excuse my newbie post and suggest the best way to do this? I have many SQL books in front of me but can’t find anything relating to this.

  • 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-16T11:29:13+00:00Added an answer on June 16, 2026 at 11:29 am

    Assuming this question doesn’t get closed, SQL Server 2012 introduces a new, to SQL Server, feature called Sequence numbers. They are similar to defining a column as an identity but they are instead just a global number dispenser—tied to nothing but themselves.

    Sequence numbers, can provide better performance versus an identity property due to fewer meta data operations required to use them as well as the ability to set an explicit cache instead of IDENTITY’s hard coded 10. Reference

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

Sidebar

Related Questions

Possible Duplicate: Best way to get identity of inserted row? When is it appropriate
Possible Duplicate: Best way to get identity of inserted row? I have an INSERT
Possible Duplicate: best way to get the key of a key/value javascript object foo
Possible Duplicate: Best way to get InnerXml of an XElement? I am using an
Possible Duplicate: Best way to get files from a dir filtered by certain extension
Possible Duplicate: What is the best way to get and set a single cookie
Possible Duplicate: best way to get value from Collection by index Say I have
Possible Duplicate: Best way to get files from a dir filtered by certain extension
Possible Duplicate: Whats the best way to get total # of records in a
Possible Duplicate: Best way to find Browser type & version? In HTML/JavaScript, How can

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.