Scenario:
We have a dbo.Customer table that has ID as identity column. We need to insert one record in this table with -1 for ID.Solution :
We will be using Identity_insert ON and Off to do this as shown below.It will disable identity property and then we will insert record and then enable it back.
CREATE TABLE dbo.Customer(
ID INT IDENTITY(1,1) , CustomerCode VARCHAR(50) , FirstName VARCHAR(50) , LastName VARCHAR(50)) SET IDENTITY_INSERT dbo.Customer ON
GO
INSERT INTO dbo.Customer ( ID,CustomerCode,FirstName,LastName)
VALUES (-1,'UNKNOWN','UNKNOWN','UNKNOWN')
SET IDENTITY_INSERT Dbo.Customer OFF SELECT * FROM dbo.Customer
How to insert value in Identity Column manually in SQL Server Table
Video Demo : How to manually insert the value in identity column in SQL Server Table
|
Liên hệ Aivivu, đặt vé máy bay tham khảo
ReplyDeletevé máy bay đi Mỹ bao nhiêu tiền
vé máy bay từ houston về việt nam
lich bay tu duc ve viet nam
khi nào có chuyến bay từ nga về việt nam
chuyến bay từ anh về việt nam
giá vé máy bay từ pháp về việt nam
khách sạn cách ly ở tphcm