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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:31:30+00:00 2026-05-14T00:31:30+00:00

I am converting to an integer primary key and am having trouble seeding the

  • 0

I am converting to an integer primary key and am having trouble seeding the new column data with a count of integer numbers.

Given an existing table:

create table t1 (
  Id uniqueidentifier, 
  NewId int,
  Data nvarchar(100)
)

How would I update existing rows with a count of numbers from 1 to the # of rows in the result set?

So:

|id      |NewId       |Data
-------------------------------
|ABC     |null        |first
|DEF     |null        |second
|GHI     |null        |third

Would become:

|id      |NewId    |Data
----------------------------
|ABC     |1        |first
|DEF     |2        |second
|GHI     |3        |third

This is for a migration to using a hilo primary key with nhibernate, which is needed to reduce database round trips with between my application and database tiers, so IDENTITY is not an option for me.

  • 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-14T00:31:31+00:00Added an answer on May 14, 2026 at 12:31 am

    You could use a windowing function like row_number:

    update t
    set NewId = sub.rn
    from YourTable t
    join (
        select
            id
        ,   row_number() over (order by id) as rn
        from YourTable
    ) sub on sub.id = t.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an efficient method of converting an integer into the written numbers, for
I'm having trouble converting a string into a double. My string has been declared
I'm having a problem with converting a formatted date string into a integer timestamp.
I was wondering if there was an alternative to itoa() for converting an integer
There are many ways of converting a String to an Integer object. Which is
How does C handle converting between integers and characters? Say you've declared an integer
There are several different methods for converting floating point numbers to Integers in JavaScript.
Converting to ODB.NET from System.Data.OracleClient and need help converting my connection string. Here is
Having some trouble with the Migrations in Sequel and could use another set of
I have method for converting array of Booleans to integer. It looks like 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.