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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:35:40+00:00 2026-06-15T03:35:40+00:00

I have a database with an ID column. Whenever there is a new entry

  • 0

I have a database with an “ID” column. Whenever there is a new entry for the database, I fetch the last ID from the database, increment the value, and then use it in the Insert statement.

EDIT : I need the ID to use in multiple Insert statements. I will fetch this ID from the primary table and use this ID to insert values into related tables.

    NextID = Select Max(ID) + 1 From Table

    INSERT INTO Table1(ID, Col1, Col2...) Values(NextId, Value1, Value2...)

    INSERT INTO Table2 (ID,col1,col2....) Values (NextID, Value1, Value2...)

I dont know if this is a good way because I know there will be concurrency issues.
When my application tries to read the NextID, there is a chance that another instance of the application is also trying to read the same value and thus concurrency issues may arise.

Is there a proper way to deal with this situation? I mean there are ways to set the database isolation level. Which would be a proper Isolation level for this situation.

Also if anybody could suggest me with an alternate way to maintain and increment manually the ID in the database, I’m also open to that.

If this information is not enough, please let me know what you require.

I am working with ASP.Net with VB and MS Sql Server 2008. I do not want to use the built-in “Identity” of SQL Server.

  • 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-15T03:35:42+00:00Added an answer on June 15, 2026 at 3:35 am

    The only way to get the next ID is to actually insert the row, and use identity. Everything else will fail. So you must start by inserting into the parent table:

    begin transaction;
    insert into Table (col1, col2, col3) values (value1, value2, value3);
    set @Id = scope_identity();
    insert into Table1(ID, col1, col2) values (@Id, ...);
    insert into Table3(ID, col1, col2) values (@Id, ...);
    commit;
    

    This is atomic and concurrency safe.

    I do not want to use the built-in “Identity” of SQL Server.

    tl;dr. What you ‘want’ matter little unless you can make a clear justification why. You can do it correctly, or you can spend the time ‘ill oblivion reinventing the wheel.

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

Sidebar

Related Questions

I have a dropdown menu that pulls in text from a database column. The
I have a database table named 'student' in which there is one column named
I have a column in my database that will be updated randomly. Whenever that
I have a SQL Server database which has a column of date with value
I have a database column that contains the contents of a file. I'm converting
So we have a database column that can contain just about anything. Unicode, numbers,
I have a database table with a column called 'symbol', that is unique via
I have some files stored in a database blob column in Oracle 9. I
I have several database tables that just contain a single column and very few
I have a textbox which is binded to a specific database table column. This

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.