You chose wisely, my son. 

-----Original Message-----
From: Chris Mueller [mailto:[EMAIL PROTECTED] 
Sent: Friday, March 10, 2006 7:11 AM
To: CF-Talk
Subject: Re: SQL-generated primary keys

Thanks everyone for all your help! 

I am using SQL server, and have reworked my queries to use SCOPE_IDENTITY().

Chris

>If it is SQL Server, do this
>
><cfquery>
>       Insert into () Values ();
>       SELECT  SCOPE_IDENTITY() AS id
></cfquery>
>That will give you the correct identity id
>
>Sandra Clark
>-----Original Message-----
>From: Chris Mueller [mailto:[EMAIL PROTECTED]
>Sent: Thursday, March 09, 2006 4:35 PM
>To: CF-Talk
>Subject: SQL-generated primary keys
>
>Here's a question I've been wrestling wtih.
>
>Suppose that there is an HTML form to create a new user. When the form 
>is submitted, that user's information is added to the 'user' table.
>The table uses an auto-increment integer for its primary key/user id, 
>so I'd like to grab that value for the newly created user.
>
>I've been using queries like this one: "SELECT MAX(user_id) FROM 
>users", but I worry that if two users are created at the same time, 
>then my query might give me the user id of the wrong user.
>
>Is there a better way to do this? Or maybe I shouldn't even worry about 
>this?
>
>Thanks.
>Chris



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:235110
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=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to