Last active
April 22, 2016 18:08
-
-
Save daniel-liuzzi/fb0861f85c4ee8b7e87684fc66ad5bad to your computer and use it in GitHub Desktop.
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
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; | |
DROP TABLE MyTableCopy; | |
DROP TABLE SourceTable; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment