| How to
use the IDENTITY_INSERT switch? |
|
Execute the following
script in Query Editor to demonstrate the usage of IDENTITY_INSERT table property.
USE AdventureWorks
GO
SELECT * from Person.ContactType
GO
-- the following will fail
INSERT Person.ContactType(ContactTypeID, [Name])
VALUES (1000, 'Email Support')
GO
-- the following will succeed
SET IDENTITY_INSERT Person.ContactType ON
INSERT Person.ContactType(ContactTypeID, [Name])
VALUES (1000, 'Email Support')
SET IDENTITY_INSERT Person.ContactType OFF
GO
SELECT * from Person.ContactType
GO
DELETE Person.ContactType WHERE ContactTypeID=1000
GO
SELECT * from Person.ContactType
GO
|
| The Best SQL Server
2005 Training in the World |
|