13 Ocak 2012 Cuma

Tsql ile OUTPUT kullanımı



We will first begin our work with the OUTPUT clause, by diving into hands-on examples of deleting, inserting, and updating table data. Later, we will demonstrate logging these types of changes in a separate storage table. Note: The OUTPUT statement uses temporary INSERTED and/or DELETED tables. These memory-resident tables are used to determine the changes being caused by the INSERT, DELETE or UPDATE statements.

  • Delete Actions with output
           You must use ;
?
1
DELETE FROM [TableName] OUTPUT Deleted.[ColumnNames] WHERE [ColumnName] like '%Faruk%'


  • Update Actions with output
           You must use ;
?
1
UPDATE [TableName] SET [ColumnNames] = [Values] OUTPUT Delete.*, Inserted.* WHERE [ColumnNames] = [Values]


  •  Insert Actions with output
            You must use ;
           INSERT INTO [TableName] OUTPUT Inserted.* VALUES(7,'555 CanDo St','Portland','OR')

         The result so see u later ;-)


Kaynak : http://www.farukalkaya.com/Blog/post/2011/08/14/Tsql-output-clause-with-examples-(delete-insert-update).aspx

Hiç yorum yok: