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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:39:59+00:00 2026-05-29T10:39:59+00:00

I added a new identity column, and I need to update it so that

  • 0

I added a new identity column, and I need to update it so that the id column goes into the identity column, then delete the old id column and rename the identity column, because you cannot change a column to an identity.

I don’t know how to do this, I guess I want to loop through each row, insert it into the same table, setting the identity field to match the id field (using IDENTITY_INSERT) but I am not familiar with loops in SQL. Any ideas?

  • 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-29T10:40:00+00:00Added an answer on May 29, 2026 at 10:40 am

    You could do it with temp table something like this:

    Sample table and data

    create table xx
    (
      OldID int
    )
    
    insert into xx values(10),(20),(30)
    

    Add NewID as identity and get the value from OldID.

    create table xxTmp
    (
      OldID int,
      [NewID] int identity
    )
    
    set identity_insert xxTmp on
    
    insert into xxTmp(OldID, [NewID])
    select OldID, OldID
    from xx
    
    set identity_insert xxTmp off
    
    drop table xx
    exec sp_rename 'xxTmp', 'xx'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I added a new subdir within my git respository: git add feeds Then commited
NOTE: I added my new solution at the UPDATE answer below. I try to
Scenario: I have a fairly generic table (Data), that has an identity column. The
I added a new feature into an app which I'm updating for the app
I removed my .gitconfig by accident. I added new identies by git add [file]
I added a new file F1 and made changes to another file F2 but
I added a new field to a stored procedure. How do I get it
I've accidentally added a new filter to my GAE application. The status of the
I have added a new job in my hudson server which builds the project
I've setup IIS6 to work with MVC, added a new virtual web site, entry

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.