|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Wednesday, November 04, 2009 3:30 AM
Points: 771,
Visits: 108
|
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Tuesday, November 03, 2009 9:39 PM
Points: 75,
Visits: 38
|
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, November 16, 2009 5:09 AM
Points: 18,
Visits: 13
|
|
Beside some missing spaces in the code, which is confusing, I miss information how the Output option returns its values to the devolper.
Kindest Regards,
DoktorBlue
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, September 16, 2009 5:59 AM
Points: 21,
Visits: 26
|
|
Very valuable information to me. Too bad that te conclusion is wrong! There really is a need to perform modifications wherever @@identity or scope_identity() is used because they are not reliable: - after a rollback, the assigned identity is returned while it does not exist
- when some other identity is assigned (in any table) between your insert and reading out @@identity you get that other identity
So, my conclusion would be that it really is nescessary to rewrite code whenever you need the newly assigned identity. Regards, Hans van Dam
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Tuesday, October 20, 2009 2:17 AM
Points: 57,
Visits: 31
|
|
Yes indeed. Very valuable feature. Performance can be greatly enhanced by this, where triggers may be replaced. Those wondering about the missing spaces... In the first example block, SELECTSCOPE_IDENTITY() should be SELECT SCOPE_IDENTITY(). In the last example block where the delete statements are WHEREID = should be WHERE ID = 
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, April 28, 2009 6:37 AM
Points: 1,
Visits: 3
|
|
| Useful tip, but I think the editor should have done more editing (and proofreading.)
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Wednesday, November 18, 2009 10:41 AM
Points: 940,
Visits: 177
|
|
| Missing some key information such as when you cannot use it. Will not work if there is a trigger on the table, or if it is involved in foreign key, or has check constraints. All of those are pretty common.
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Wednesday, November 04, 2009 3:30 AM
Points: 771,
Visits: 108
|
|
sorry for the query errors
My Blog: http://dineshasanka.spaces.live.com/
|
|
|
|
|
SSCertifiable
       
Group: Moderators
Last Login: 2 days ago @ 6:28 AM
Points: 6,361,
Visits: 900
|
|
Jimi, that's not quite correct. Here's what it says in BOL: output_table cannot: - Have enabled triggers defined on it.
- Participate on either side of a foreign key constraint.
- Have CHECK constraints or enabled rules.
You can use it on any table regardless of configuration, it's only the output table where you're landing the results that has restrictions. The output clause is one of the really nice improvements in 2005. I've seen all too many instances where developers were essentially inserting an alternate primary key so that they could insert multiple rows at once and still get the keys back. If they had used scope_identity() they would have been forced to insert the records one at a time which is not great for performance. Essentially the output clause exposes the logical inserted and deleted tables that were previously only visible within the trigger execution.
Andy SQLShare - Learn One New Thing Each Day It Depends - My Professional Blog
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Wednesday, November 04, 2009 3:30 AM
Points: 771,
Visits: 108
|
|
Andy, is it possible you to do following changes in the article SELECTSCOPE_IDENTITY() should be SELECT SCOPE_IDENTITY() in first example block. In the last example block where the delete statements are WHEREID = should be WHERE ID
My Blog: http://dineshasanka.spaces.live.com/
|
|
|
|