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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:50:26+00:00 2026-05-26T17:50:26+00:00

My goal is to insert a new and unique(unique is very important) number into

  • 0

My goal is to insert a new and unique(unique is very important) number into a MySQL table on the server every time upon an event on a user’s machine, using ajax.

So, server’s part on user’s event is doing this (using php):

  • Finds a maximum value from the column in the db,
  • Adds 10 to a maximum value,
  • this is a new and unique (bigger than a maximum) value, we insert insert into a table.

Will all numbers be unique and go like 1, 11, 21, 31, if it starts from 1? I’m curious if inserting into the Table finishes before it starts performing another queue and coule be like 1, 11, 21, 21, 31, 41?

If it theoretically works like this (ordered by time)

  1. find max value from the column for the first user
  2. find max a value from the column for the second user (it will be the same)
  3. insert a (max+10) for the first user into the same table
  4. insert a (max+10) for the second user into the same table (it will be the same), then the results will be the same, and 1 value could be repeated twice or even more…

So, the question is: will all numbers be 100% unique?
Depending on this I have to choose which algorithm to use for creating unique numbers.

Added:
Is it possible to be sure with this algorythm and without using autoincrements? Autoincrement is used for another column. Holes between numbers are OK. The only requirement is that numbers should be different, but with some “delta” that is more than one. Sorry I didn’t notice about that in my question. Thank you.

  • 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-26T17:50:27+00:00Added an answer on May 26, 2026 at 5:50 pm

    Unless you have a very specific reason against it, I recommend using AUTO_INCREMENT – it will scale much better and actually leave fewer “holes” in the sequence of numbers than your approach.

    And you are correct – your approach will not actually guarantee uniqueness in concurrent environment. One way to make your algorithm work is to have a UNIQUE constraint on your field (if it is not already PRIMARY KEY) and then repeatedly attempt to insert a new value – if it fails just generate a new value and try again and it will eventually succeed.

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

Sidebar

Related Questions

My goal is to insert a variable's value directly into a string without concatenation
My goal is sql-escaping in bulk-insert query. Eg: INSERT INTO log VALUES (0,5,-7,'str'), (4,0,0,'str'),
My goal is to add a insert new value to a column where my
I am wanting to insert a datetime into a MySql data base using Java
My goal is to achieve delete all recommendations and then insert new. (any online
The goal of this trigger is to insert old data per row into a
I insert data into sqlite database table and when i insert first record ,
Possible Duplicate: Function to Calculate Median in Sql Server Goal: Display the value of
The code below will insert an actionlink into one of the web grids' columns.
I am trying to insert nodes in my html string. My goal is to

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.