Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Add Identity Key behaviour to existing primary key column.

Add Identity Key behaviour to existing primary key column.

Scheduled Pinned Locked Moved Database
questiondatabasesql-serversysadmin
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    Xandip
    wrote on last edited by
    #1

    Hi guys, Back with another question :) Create Table TestTable ( TestTableId Int Not Null, TestTableName Varchar(100), Primary Key (TestTableId) ); Now i want to alter the TestTableId column and change it to an Identity Key. I heard that theres no direct syntax for this as such. But is this possible through SQL Server 2008?

    The name is Sandeep

    W 1 Reply Last reply
    0
    • X Xandip

      Hi guys, Back with another question :) Create Table TestTable ( TestTableId Int Not Null, TestTableName Varchar(100), Primary Key (TestTableId) ); Now i want to alter the TestTableId column and change it to an Identity Key. I heard that theres no direct syntax for this as such. But is this possible through SQL Server 2008?

      The name is Sandeep

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      As far as I know it's not possible in SQL Server 2008 either. Why not use temp table in the process, like: - create temp table as you want the table to be - set IDENTITY_INSERT ON - copy the data to temp table using INSERT INTO ... SELECT ... - set IDENTITY_INSERT OFF - drop the original table - rename the temp table to orginal table using sp_rename

      The need to optimize rises from a bad design. My articles[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups