OUTPUT Clause
OUTPUT ile eklenen, silinen ve güncelleme yapılan tablolardaki hareketleri sadece sayısal değil değerleri ile birlikte gözlemleyebiliriz.
MSDN açıklaması:
Returns information from, or expressions based on, each row affected by an INSERT, UPDATE, or DELETE statement. These results can be returned to the processing application for use in such things as confirmation messages, archiving, and other such application requirements. Alternatively, results can be inserted into a table or table variable.
USE tempdb
go
CREATE TABLE table1
(
id INT,
employee VARCHAR(32)
)
go
INSERT INTO table1 VALUES(1, 'Fred')
INSERT INTO table1 VALUES(2, 'Tom')
INSERT INTO table1 VALUES(3, 'Sally')
INSERT INTO table1 VALUES(4, 'Alice')
GO
DECLARE @MyTableVar TABLE
(
id INT,
employee VARCHAR(32)
)
PRINT 'table1, before delete'
SELECT * FROM table1
DELETE FROM table1
OUTPUT DELETED.* INTO @MyTableVar
WHERE id = 4 OR id = 2
PRINT 'table1, after delete'
SELECT * FROM table1
PRINT '@MyTableVar, after delete'
SELECT * FROM @MyTableVar
DROP TABLE table1
http://msdn.microsoft.com/en-US/library/ms177564(v=SQL.90).aspx
No comments:
Post a Comment