This is certainly the best and most natural way to create a unique  
primary key, and certainly the way I prefer, however the issue is what  
to do in instances where you want to create a unique primary key on  
insert, then return the key to the calling code in such a way that is  
database independent.  In other words, how can you write code that will  
insert a row and return the ID of the row that was inserted if you  
can't count on "SELECT @@identity" or "curval('id')"?  It's all  
explained in the weblog post:

http://markme.com/cantrell/weblog/index.cfm?m=3&d=17&y=2003

For the record, if you do not need your code to be database  
independent, I would certainly advocate using an auto-incrementing  
column rather than the techniques we are discussing here.  But these  
are some pretty interesting alternatives.

Christian

On Monday, March 17, 2003, at 05:35 PM, <[EMAIL PROTECTED]>  
wrote:

> FlashGuy,
>
> This ID is for your DB right?  Why not generate it as you insert your  
> row of data?  Create a PK say ID and make a sequence of it that auto  
> increases on insert.  This will give you uniqueness.
>
>
> Doug
>
>> -----Original Message-----
>> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
>> Sent: Monday, March 17, 2003 5:21 PM
>> To: CF-Talk
>> Subject: Re: Using createUUID()
>>
>>
>> Using the maxid trick has problems though.  In some databases,
>> it will create a race condition.  The only way to alleviate it
>> is to set the transaction isolation level to "serializable".
>>
>> ----- Original Message -----
>> From: Matt Robertson <[EMAIL PROTECTED]>
>> Date: Monday, March 17, 2003 2:53 pm
>> Subject: Re: Using createUUID()
>>
>>> Chris,
>>>
>>> I've used the method you describe for awhile and prefer it.  Your
>>> post reminded me of another method that seems safe, but I never
>>> went there.  CF_MaxID:
>>>
>>> http://tinyclick.com/?T02MT2
>>>
>>> You need a transaction block inside of a try/catch block inside of
>>> a loop to make it bombproof (:O) per the included docs, but it'll
>>> apparently work without adding a second indexed field to your table.
>>>
>>> -------------------------------------------
>>> Matt Robertson,     [EMAIL PROTECTED]
>>> MSB Designs, Inc. http://mysecretbase.com
>>> -------------------------------------------
>>>
>>>
>>> ---------- Original Message ----------------------------------
>>> From: Christian Cantrell <[EMAIL PROTECTED]>
>>> Reply-To: [EMAIL PROTECTED]
>>> date: Mon, 17 Mar 2003 15:22:12 -0500
>>>
>>>> I posted some information on the createUUID function on my weblog
>>> today
>>>> based on an application I was working on over the weekend:
>>>>
>>>> http://www.markme.com/cantrell/weblog/index.cfm?m=3&d=17&y=2003
>>>>
>>>> Christian
>>>>
>>>> On Monday, March 17, 2003, at 07:55 AM, FlashGuy wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I need to generate a unique ID for every form I submit. The
>>> createUUID
>>>>> # generated is just too long for my needs. My ID only needs to
>>> be 10
>>>>> characters in length. Something like:
>>>>>
>>>>> CT-0001001
>>>>>
>>>>> I'm using MySQL. Can I have mysql generate the unique ID? How
>>> could I
>>>>> do this with CF?
>>>>
>>>>
>>>
>>
> 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
This list and all House of Fusion resources hosted by CFHosting.com. The place for 
dependable ColdFusion Hosting.

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
                                

Reply via email to