Created
April 5, 2016 14:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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