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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:50:19+00:00 2026-05-24T02:50:19+00:00

If I have ID column, which is a primary key and Identity is set

  • 0

If I have ID column, which is a primary key and Identity is set to TRUE, inserting each row should increment my ID. My question is, if I have 100 rows and a function (somewhere in the code) to select random row (rand(1,101)), how to deal with a situation, when I delete a row and random function fails if the one was selected. I could manage this exception in the code, but wonder if there is a way in SQL to fill these deleted row gaps with continues IDs.

  • 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-24T02:50:19+00:00Added an answer on May 24, 2026 at 2:50 am

    Guessing SQL Server because of “Identity”

    Use TOP 100.. ROW_NUMBER() instead to generate 100 contiguous values and filter on that value.

    Or use TOP 1..ORDER BY NEWID() to choose a random row.

    Internal IDENTITY values have no meaning except as a surrogate key. Note an INSERT fail also increments the IDENTITY value, not just deletes.

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

Sidebar

Related Questions

I have many tables; each has a primary key which is an Identity column
I have a non-nullable database column which has a default value set. When inserting
I have a table Administrator with only one column, adminId which is the primary-key.
I have a database table with the primary column defined as: ID bigint identity
Possible Duplicate: Adding an identity to an existing column how to set auto increment
I have a column which is of type nvarchar(max). How do I find the
I have a column which has a datatype : datetime. But now i want
Hi I an issue with editors in a JTable. I have a column which
I have an xml column which contain data like this: <AuthorList CompleteYN=Y> <Author ValidYN=Y>
In SQL Server I have a DATETIME column which includes a time element. Example:

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.