DEFINITIONS

Definitions More Info.
Definition ID229
TitleSQL
CategorySCRIPT
DefinitionINSERT WITH OUTPUT CLAUSE
Definition Description-- Alter table so Id column is now an identity
ALTER TABLE Fruit DROP Column Id;
ALTER TABLE Fruit ADD Id int identity;
-- Create table variable to hold output from insert
DECLARE @INSERTED as TABLE ( Id int, Name varchar(100));
--INSERT with OUTPUT clause
INSERT INTO Fruit (Name, Color) OUTPUT INSERTED.Id, INSERTED.Name INTO @INSERTED VALUES ('Bing Cherries','Purple'), ('Oranges','Orange');
-- view rows that where inserted
SELECT * FROM @INSERTED;
RecordBycunay
Record Date15-08-2012 12:08:34
Düzenle
Kopyala
Sil