Interesting, never had a problem with @@IDENTITY though. It seems to me that
unless you're using triggers, it's pretty much impossible for it to return
the wrong value in a query like the example below.

SCOPE_IDENTITY() certainly looks a little safer but I'm not worried about
all my old code.

Craig.

-----Original Message-----
From: Matt Williams [mailto:[EMAIL PROTECTED] 
Sent: 19 August 2008 16:57
To: CF-Talk
Subject: Re: CFC Best Practices

On Tue, Aug 19, 2008 at 10:44 AM, Craig Dudley <[EMAIL PROTECTED]> wrote:
> Rob, if you are using MSSQL why don't you use @@IDENTITY?

Just to be clear, @@identity returns the most recent inserted id of
all tables. So if you had a trigger that when a table gets an insert,
another table also gets an insert, @@identity would return the
triggered table ID.

For SQL 2000 +, look at SELECT SCOPE_IDENTITY() or SELECT
IDENT_CURRENT('tablename').

http://www.sqlteam.com/article/alternatives-to-identity-in-sql-server-2000

I've seen other good blog entries / articles about this, but couldn't
locate them at the moment.

-- 
Matt Williams
"It's the question that drives us."



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;203748912;27390454;j

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:311269
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to