Identity reset issue

189 Views Asked by At

Possible Duplicate:
SQL server identity column values start at 0 instead of 1

Inserted identity value starts from "0"

Here I'll create a database and create a table, now I'll try to delete the records in the empty table and reset the identity. When i insert the records now its starts from identity value "0".

CREATE DATABASE test

GO

USE test

CREATE TABLE [dbo].[table1]
  (
      [Rollno] [int] IDENTITY(1,1) NOT NULL,
      [Name] [nvarchar](max) NOT NULL,
    CONSTRAINT [PK_Images] PRIMARY KEY CLUSTERED
    (
        [Rollno] ASC
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
  )ON [PRIMARY]

USE test

DELETE TABLE table1

DBCC CHECKIDENT('table1', RESEED, 0)

INSERT INTO table1 VALUES('Sachin')

SELECT * FROM table1

Could any one please help me to resolve this.

2

There are 2 best solutions below

0
On

Try using DBCC CHECKIDENT('table1', RESEED, 1)

The last argument is the next value to use for the identity column.

0
On

You are reseeding the identity value to 0, so this is the expected behaviour.