>> Jacob Munson wrote: >> > Unless someone has created a new record after your >> > insert, >> > then you'll get their identity instead. >> > SCOPE_IDENTITY, >> > on the other hand, returns the last identity value >> > generated for any table in the current session and the >> > current scope. So with one, you might get someone >> > else's identity, and with the other you might get the >> > wrong table. >> >> Nope that's not true. scope_identity() works on the last >> table >> specified in the current batch.
> I actually copied this line from BOL: "SCOPE_IDENTITY, > returns the last > identity value generated for any table in the current > session and the > current scope." So it doesn't matter what table you > inserted into, it > will get the most recent identity field you created for > the scope and > session. However, I think that's saying the same thing > you are. The > danger is if you forget and do more than one insert, and > then grab > scope_identity, which is a dumb programmer mistake not a > database > problem. I thought I remembered it using the word "batch" in the docs, but I must be mistaken... in any event, the "scope" is the batch. :P As evidenced by the test case... (Actually it's not technically the batch because if it's used within a stored procedure, then the scope is the procedure, but I digress)... but yeah, if you perform two inserts you have to be careful about where you place the scope_identity() in your batch, which does make it a coding issue. s. isaac dealey 434.293.6201 new epoch : isn't it time for a change? add features without fixtures with the onTap open source framework http://www.fusiontap.com http://coldfusion.sys-con.com/author/4806Dealey.htm ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:236985 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

