On 6/4/05, Barney Boisvert <[EMAIL PROTECTED]> wrote:
> Mostly because it doesn't require an index lookup like using the MAX
> function does.  MySQL internally records the last inserted value for
> recall with the LAST_INSERT_ID function, exactly as MS SQL does with
> the @@IDENTITY variable (and the other two variants).  The MAX method
> will work on any DB (well, at least any decent one) without issue, but
> it's pretty much guarenteed to be slower than the built-in "get the
> last ID" mechanism for a given database, perhaps by a large margin.

Another reason not to use the Max(ID) approach is that you run into
problems if someone, for whatever reason, manually inserts an ID value
into the table that's larger than the current "next id" value. This
causes all sorts of weird problems in test databases and databases
that have been exported/imported.

You want the *just inserted id*, not the maximum of the id's already
inserted. That value is usually the same as the max, but you shouldn't
automatically count on it
 
> cheers,
> barneyb
> 
> On 6/4/05, Aaron Rouse <[EMAIL PROTECTED]> wrote:
> > I am not familar with MySQL but what would be the advantage of using that
> > function over just using
> >
> > <cftransaction>
> > <cfquery ...>INSERT INTO myTABLE (myCOLUMNS) VALUES (myVALUES)
> > </cfquery>
> > <cfquery ... name="get">
> > SELECT MAX(ID) AS NewID FROM myTABLE
> > </cfquery>
> > </cftransaction>
> >
> > <cfoutput>NewID = #Get.NewID#</cfoutput>
> >
> 
> --
> Barney Boisvert
> [EMAIL PROTECTED]
> 360.319.6145
> http://www.barneyb.com/
> 
> Got Gmail? I have 50 invites.
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

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