Example of How to use set IDENTITY_INSERT

,

a Basic example of how to manipulate an IDENTITY COLUMN
AN HOW TO STOP the automatic counting using SET IDETNTITY_INSERT

SET NOCOUNT ON
CREATE TABLE #famousceasars
(cid int identity,
 jc varchar(15),
 occupation varchar(25),
 becamefamous int DEFAULT 0,
 notes text NULL
 )

SET IDENTITY_INSERT #famousceasars ON
INSERT #famousceasars(cid,jc,occupation,becamefamous,notes) 
VALUES (1,'Julius Caesar','Military leader/dictator',DEFAULT,NULL)
SET IDENTITY_INSERT #famousceasars OFF

SELECT * FROM #famousceasars
GO
DROP TABLE #famousceasars

Rate

Share

Share

Rate