Oct 28, 2008

MS SQL 2005 identity lost new database - Database Journal Forums – Database Forum for Access, DB2, SQL, Oracle & More

creating a TABLE

CREATE TABLE [dbo].[TbTest](
[id_TbTest] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED ,
[Title] [varchar](100) NULL,
) ON [PRIMARY]


when looking at the Column Properties in MS Server Management Studio you can get :
Identity Specification = Yes
(Is Identity) = Yes
Increment = 1
Seed = 1

now if you want to make a copy of that database, importing data and tables

you will get :
Identity Specification = No
(Is Identity) = No

Solution

"It is impossible alter column to type IDENTITY directly, but you can do it in few steps:

ALTER TABLE [dbo].[TbTest] ADD
[id1_TbTest] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED;
ALTER TABLE [dbo].[TbTest] DROP COLUMN [id_TbTest];
EXEC sp_rename '[TbTest].[id1_TbTest]', 'id_TbTest', 'COLUMN';"