Wednesday, February 27, 2013

how to ressed identity

USE [tempdb]
GO
CREATE TABLE [dbo].[Test](
    [ID] INT IDENTITY(1,1) NOT NULL,
    [Name] [varchar](10) NULL
)



INSERT INTO Test (Name)
VALUES('JIM'),('NICK'),('Thomas')

SELECT * FROM test

DELETE FROM   test

INSERT INTO Test (Name)
VALUES('Ray'),('Andrew'),('TIM')


SELECT * FROM Test
you would see the id starts FROM 4 ,so do a reseed to get identity back to what ever position we need , i need to start ID with 1 so

DELETE FROM test

DBCC CHECKIDENT ('Test ', RESEED, 0)
GO
INSERT INTO Test (Name)
VALUES('Ray'),('Andrew'),('TIM')

SELECT * FROM test

Thanks

No comments:

Post a Comment

https://blog.sqlauthority.com/2009/06/27/sql-server-fix-error-17892-logon-failed-for-login-due-to-trigger-execution-changed-database-context...