SQL Server 2005 T-SQL New Features: OUTPUT

Friday Jan 6th 2006 by DatabaseJournal.com Staff
Share:

SQL Server 2005 has T-SQL enhancements to make common tasks easier. Although @@IDENTITY and SCOPE_IDENTITY() are still supported, you’ll probably find the OUTPUT clause a more convenient choice for knowing what values your queries are generating.

[From DBAzine]

While it is convenient to have SQL statements generate values, it can be problematic if the generated values need to be known and used. For example, it is a widespread and common practice to define a table using IDENTITY to populate primary key values during INSERT statements. Sometimes, there is a need to know the IDENTITY value immediately after an INSERT statement is completed — perhaps, to do INSERTs into child tables. Additionally, when tables have default values set by functions such as GETDATE(), there are times when these values need to be known after the INSERT. Similarly, an UPDATE statement can explicitly set a column’s new value to a value known only at execution time (e.g., setting the current date and time to GETDATE() or calculating the value of a computed column).

The article continues at http://www.dbazine.com/sql/sql-articles/cook18/

Share:
Home
Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved