Question: Does this initialize itself? If there is no data, will that query
assume a 0 and start off at 1?

I like this much better then using the Key in access, in that in Access it
is a HARD key.. once a record is deleted, the key won't be reused and I have
gaps in my listings. This method is a real world implementation, nice code.

Scott M. Berry
--
College of the Canyons Web Design
661.259.7800 x3630
http://www.coc.cc.ca.us

----- Original Message -----
From: "Jennifer" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, May 02, 2000 10:48 AM
Subject: Re: Getting Key Field after Insert


> At 12:54 PM 5/2/00 -0400, you wrote:
> >I am using Microsoft Access Autonumber to create Key fields for me.
> >
> >1.  Is this a wise thing to do?
> >2.  If  ok , anyone have  a nice way of getting the key back.  I am
currently
> >saving a temporary key in one the fields, then finding and changing.
This
> >seams like a lot of work to create an Insert.
> >3.  If not, and this might explain all of the discussion about key
creation,
> >what was the consensous on the best way to generate a unique key?
>
> I generate keys in the page. That way, I don't have to search the database
> for the key-- I already have it. For this method, it is extremely
important
> that you use CFTransaction. Otherwise you might get errors.
>
> <cftransaction>
>                          <cfquery name="GetID"
datasource="#application.Dsn#">
>                                  SELECT MAX(UserID) as LastId
>                                  FROM table;
>                          </cfquery>
>
>                          <cfset form.UserID=(GetId.LastID + 1)>
>
>                          <cfquery datasource="#application.Dsn#">
>                          insert into table
>                          (column) values (#column#');
>                          </cfquery>
>
> </cftransaction>
>
> This code selects the largest ID number, adds one to it and sets that as
> the ID number of the new record. If you don't put this code in
> cftransaction, multiple simultaneous users could send records with the
same
> id number. This method was recommended to me by Mr GuruMan Raymond Camden,
> and I've seen it mentioned here many times. It seems to be a relatively
> standard method. I haven't had any problems with it.
> --------------------------------------------------------------------------
----
> Archives: http://www.eGroups.com/list/cf-talk
> To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to [EMAIL PROTECTED] with 'unsubscribe' in
the body.
>

------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to