Skip to content

Instantly share code, notes, and snippets.

View daniel-liuzzi's full-sized avatar

Daniel Liuzzi daniel-liuzzi

  • Barcelona
View GitHub Profile
CREATE TABLE SourceTable (Id int IDENTITY(1,1), Name nvarchar(50) NOT NULL);
INSERT INTO SourceTable VALUES ('Superman'), ('Batman'), ('Homer Simpson');
SELECT TOP 0 * INTO MyTableCopy FROM SourceTable;
-- Commenting out the following line gives "Cannot insert explicit value for identity column in table 'MyTableCopy' when IDENTITY_INSERT is set to OFF."
SET IDENTITY_INSERT MyTableCopy ON;
INSERT INTO MyTableCopy (Id, Name) SELECT Id, Name FROM SourceTable;