> I'm looking through someone elses code and I came across this...
> 
> <cftransaction>
>       <cfquery name="qInsertData" datasource="#APPLICATION.dsn#">
>               INSERT INTO t_doctors (#ColNames#)
>               VALUES (#preserveSingleQuotes(ColValues)#)
>       </cfquery>
> </cftransaction>
> <!--- pull the pkey back out --->
> <cftransaction>
>       <cfquery name="get_new_pkey" datasource="#APPLICATION.dsn#">
>               SELECT @@identity AS newpkey
>       </cfquery>
> </cftransaction>                                                      
> 
> having the queries in separate transactions doesn't do 
> anything at all, does it?  

No, not a thing. The point of variables like @@IDENTITY (and functions like
SCOPE_IDENTITY()) are to allow you to retrieve the newly created primary key
without running multiple queries and having to worry about transactional
logic, anyway.

> Wouldn't the whole thing need to be wrapped in cftransaction for 
> it to be effective?

In this particular case, you wouldn't really need the CFTRANSACTION tags at
all. Ideally, you'd just put both SQL statements together in a single batch,
or use a stored procedure or a trigger to get your primary key. But if you
couldn't do that, and therefore did need a CFTRANSACTION, it would have to
wrap both queries to make them into a single transaction.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/

Fig Leaf Software provides the highest caliber vendor-authorized
instruction at our training centers in Washington DC, Atlanta,
Chicago, Baltimore, Northern Virginia, or on-site at your location.
Visit http://training.figleaf.com/ for more information!


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:236897
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

Reply via email to