Skip to content

Instantly share code, notes, and snippets.

@vendettamit
Created April 5, 2016 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vendettamit/00edbc53acded9e8b38ca20d91532e0d to your computer and use it in GitHub Desktop.
Save vendettamit/00edbc53acded9e8b38ca20d91532e0d to your computer and use it in GitHub Desktop.
Demo scripts replicating the scenario where Trunc would reset the Reseeded identity column in existing table
USE [YourDb]
GO
-- Create Table
CREATE TABLE [dbo].[TestTable](
[ID] [int] IDENTITY(11,1) NOT NULL,
[Var] [nchar](10) NULL,
[Dated] DateTime default CURRENT_TIMESTAMP
) ON [PRIMARY]
GO
-- Build sample data
INSERT INTO [TestTable]
VALUES ('val', GETDATE())
GO
-- Select Data
SELECT *
FROM [TestTable]
GO
-- Reseed
DBCC CHECKIDENT ('TestTable', RESEED, 1)
GO
-- Build sample data
INSERT INTO [TestTable]
VALUES ('val', GETDATE())
GO
-- Select Data
SELECT *
FROM [TestTable]
GO
-- Truncate table
TRUNCATE TABLE [TestTable]
GO
-- Build sample data
INSERT INTO [TestTable]
VALUES ('val', GETDATE())
GO
-- Select Data
SELECT *
FROM [TestTable]
GO
--Clean up
DROP TABLE [TestTable]
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment