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

  • Home
  • SEARCH
  • 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 1072821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:54:45+00:00 2026-05-16T20:54:45+00:00

I am using SQL Server 2008. One int column I used as primary key

  • 0

I am using SQL Server 2008. One int column I used as primary key but not identity column (whose value will be increased by 1 automatically). I want to convert this column to identity column. Any solutions?

thanks in advance,
George

  • 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-16T20:54:46+00:00Added an answer on May 16, 2026 at 8:54 pm

    Unfortunately, you cannot change a field to IDENTITY on an existing table.

    You should:

    • Create a new table with the IDENTITY field
    • Issue SET IDENTITY_INSERT ON for the new table
    • Insert the data into the new table
    • Issue SET IDENTITY_INSERT OFF for the new table
    • Drop the old table
    • Rename the new table to the old name.

    You can use SSMS to change the field type, it will do all this for you behind the scenes.

    Here’s a sample table:

    CREATE TABLE plain (id INT NOT NULL PRIMARY KEY)
    
    INSERT
    INTO    plain
    VALUES  (1000)
    

    and the script generated by SSMS:

    SET ANSI_PADDING ON
    SET ANSI_WARNINGS ON
    COMMIT
    BEGIN TRANSACTION
    GO
    CREATE TABLE dbo.Tmp_plain
        (
        id int NOT NULL IDENTITY (1, 1)
        )  ON [PRIMARY]
    GO
    ALTER TABLE dbo.Tmp_plain SET (LOCK_ESCALATION = TABLE)
    GO
    SET IDENTITY_INSERT dbo.Tmp_plain ON
    GO
    IF EXISTS(SELECT * FROM dbo.plain)
         EXEC('INSERT INTO dbo.Tmp_plain (id)
            SELECT id FROM dbo.plain WITH (HOLDLOCK TABLOCKX)')
    GO
    SET IDENTITY_INSERT dbo.Tmp_plain OFF
    GO
    DROP TABLE dbo.plain
    GO
    EXECUTE sp_rename N'dbo.Tmp_plain', N'plain', 'OBJECT' 
    GO
    ALTER TABLE dbo.plain ADD CONSTRAINT
        PK__plain__3213E83F1A609306 PRIMARY KEY CLUSTERED 
        (
        id
        ) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    
    GO
    COMMIT
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Microsoft SQL Server 2008. I'm not an expert with it but I
I want to sort a table in SQL Server 2008 by using one column
I am using SQL Server 2008 Enterprise. I have a table and one of
I'm using SQL Server 2008. I have a table Customers customer_number int field1 varchar
i'm using SQL Server 2008 and, in one of my tables, i implemented a
I'm using SQL Server 2008. Say I create a temporary table like this one:
Using SQL Server 2008 R2 we are looking for a way to select the
Using SQL Server 2008. I have multiple Locations which each contain multiple Departments which
Using SQL Server 2008, is there a way to allow inserts to a table
using : SQL Server 2008 R2, Entityframework 4.3.1 my scenario : I read my

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.