Also laut http://msdn.microsoft.com/de-de/library/ms188059.aspx
geht das ja so:
-- SET IDENTITY_INSERT to ON.
SET IDENTITY_INSERT dbo.Tool ON
GO
-- Try to insert an explicit ID value of 3.
INSERT INTO dbo.Tool (ID, Name) VALUES (3, 'Garden shovel')
GO
Was ich aber nicht ganz verstehe ist: wenn du wie unten beschrieben ein create table statement mit identity-spalte abgesetzt hast, warum stellst Du das identity-Insert nochmal explizit an?
Wenn Du eine Tabelle erstellst
CREATE TABLE dbo.Tmp_NewProduct
(
Prod_ProductID int NOT NULL IDENTITY (1, 1),
Prod_CreatedBy int)
und mit
Insert into dbo.Tmp_NewProduct (Prod_CreatedBy)
Select Prod_CreatedBy
FROM dbo.NewProduct
fügt er doch autamtisch die Datensätze mit einer neuen ID ein.
geht das ja so:
-- SET IDENTITY_INSERT to ON.
SET IDENTITY_INSERT dbo.Tool ON
GO
-- Try to insert an explicit ID value of 3.
INSERT INTO dbo.Tool (ID, Name) VALUES (3, 'Garden shovel')
GO
Was ich aber nicht ganz verstehe ist: wenn du wie unten beschrieben ein create table statement mit identity-spalte abgesetzt hast, warum stellst Du das identity-Insert nochmal explizit an?
Wenn Du eine Tabelle erstellst
CREATE TABLE dbo.Tmp_NewProduct
(
Prod_ProductID int NOT NULL IDENTITY (1, 1),
Prod_CreatedBy int)
und mit
Insert into dbo.Tmp_NewProduct (Prod_CreatedBy)
Select Prod_CreatedBy
FROM dbo.NewProduct
fügt er doch autamtisch die Datensätze mit einer neuen ID ein.
Comment