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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:37:04+00:00 2026-06-04T00:37:04+00:00

I have got an over 500 rows table with a column called ID which

  • 0

I have got an over 500 rows table with a column called ID which is of datetype INT. Currently the values are all NULL.

What I want to achieve is to populate the ID column with an incremental number for each row, say 1, 2, 3, 4, …, 500 etc.

Please give me a help with any idea how to achieve this by SQL script.

  • 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-04T00:37:05+00:00Added an answer on June 4, 2026 at 12:37 am

    using ROW_NUMBER in a CTE is one way, but here’s an alternative; Create a new id1 column as int identity(1,1), then copy over to id, then drop id1:

    -- sample table
    create table myTable(id int, value varchar(100));
    
    -- populate 10 rows with just the value column
    insert into myTable(value)
    select top 10 'some data'
    from sys.messages;
    go
    
    -- now populate id with sequential integers
    alter table myTable add id1 int identity(1,1)
    go
    update myTable set id=id1;
    go
    alter table myTable drop column id1;
    go
    select * from myTable
    

    Result:

    id          value
    ----------- -------------
    1           some data
    2           some data
    3           some data
    4           some data
    5           some data
    6           some data
    7           some data
    8           some data
    9           some data
    10          some data
    

    While you could also drop and recreate ID as an identity, it would lose its ordinal position, hence the temporary id1 column.

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

Sidebar

Related Questions

I have got a List<Problem> which I want to export to a column based
I'm trying to send a scalar value over socket which I have got with
I have got a field that has been setup to allow for Null, but
I have got method which is using Assembly.LoadFrom(...) statement and returns the supported cultures
I have got a submenu which expands from a nav menu type object when
I have two tables: poll_response (poll_id, option_id, user_id) (about 500,000 rows, with 500 unique
I have genuinely, genuinely looked ALL over the web for a basic scoring system
I have got ot the following css to make my table cell's background transparent
So, I have got following data in a MySQL table: mysql> SELECT * FROM
I have got a problem with two tables: CREATE TABLE IF NOT EXISTS `addresses`

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.