Re: SQL Gurus... obtaining the correct Incremental ID

2010-04-29 Thread James Holmes
That's quite an omission from the docs. I'll have to try this on Oracle. mxAjax / CFAjax docs and other useful articles: http://www.bifrost.com.au/blog/ On 30 April 2010 02:20, Aaron Neff wrote: > > Just wanted to also mention CF9's result_name.generatedkey. > > Please see comment @ bottom of

Re: SQL Gurus... obtaining the correct Incremental ID

2010-04-29 Thread Aaron Neff
Just wanted to also mention CF9's result_name.generatedkey. Please see comment @ bottom of online help for cfquery: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7fae.html Thanks!, -Aaron Neff >When using "set nocount on", "select @@identity as xyz" an

RE: SQL Gurus... obtaining the correct Incremental ID

2010-04-29 Thread Che Vilnonis
... obtaining the correct Incremental ID You can of course avoid the whole issue by using the result_name.IDENTITYCOL value returned from the cfquery tag (if you are on CF8 or higher). mxAjax / CFAjax docs and other useful articles: http://www.bifrost.com.au/blog/ On 29 April 2010 01:51, Che Vilnonis

Re: SQL Gurus... obtaining the correct Incremental ID

2010-04-29 Thread Michael Dinowitz
The same basic issue came up on the SQL list. http://www.houseoffusion.com/groups/sql/thread.cfm/threadid:898 While the question and result is based on a stored procedure, the same code can go in a single cfquery statement. The operation is a simple check for data existence and insert if it does

Re: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread James Holmes
You can of course avoid the whole issue by using the result_name.IDENTITYCOL value returned from the cfquery tag (if you are on CF8 or higher). mxAjax / CFAjax docs and other useful articles: http://www.bifrost.com.au/blog/ On 29 April 2010 01:51, Che Vilnonis wrote: > > When using "set nocou

Re: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread Leigh _
>YO! 2005 + > >USE OUTPUT Duh! Yes, if needed, OUTPUT is an option as well. (Though IIRC it does not work with the jTDS driver. At least not the last time I checked.) However, the primary point was there are safer alternatives to SELECT MAX(ID) ..

Re: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread Casey Dougall
age ---- > Subject: Re: SQL Gurus... obtaining the correct Incremental ID > From: Leigh _ > Date: Wed, April 28, 2010 4:44 pm > To: cf-talk > > > >That would ONLY work if you used SET TRANSACTION ISOLATION LEVEL > >SERIALIZABLE or WITH(TABLOCKX HOLDLOCK) > >

RE: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread brad
> Wouldn't READ COMMITTED do the trick? ...will never read data that another > application has changed and not yet committed No. Another process could insert a record into the table and commit its change before you select out the max. The ONLY way for the max() record to be yours is to preven

RE: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread brad
quot;SET TRANSACTION ISOLATION LEVEL SERIALIZABLE" immediately prior to the select. ~Brad -------- Original Message -------- Subject: Re: SQL Gurus... obtaining the correct Incremental ID From: Dave Watts Date: Wed, April 28, 2010 4:54 pm To: cf-talk > That would ONLY work if you used SET TRANSA

RE: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread brad
Yes, I would agree that is a much simpler and safer alternative. since scope_identity() is already specific to your connection you don't have to worry about locking and such altogether. ~Brad Original Message Subject: Re: SQL Gurus... obtaining the correct Incremental ID

Re: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread nvc 1
from cfquickdocs for cf8: "If you do not specify a value for the isolation attribute, ColdFusion uses the default isolation level for the associated database." from mssqlcity.com: "READ COMMITTED This is the default isolation level in SQL Server. When it's used, SQL Server will use shared lock

Re: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread Casey Dougall
On Wed, Apr 28, 2010 at 5:34 PM, nvc 1 wrote: > > so is this reliable? > > > > >insert into mytable(acolumn) values(1) > > >select max(id) as

Re: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread Leigh _
>That would ONLY work if you used SET TRANSACTION ISOLATION LEVEL >SERIALIZABLE or WITH(TABLOCKX HOLDLOCK) > >Even with with rowlock, another spid can insert additional records into >the table and the select max() might return a bogus value. Aside from being unsafe without the right isolation lev

Re: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread nvc 1
so is this reliable? insert into mytable(acolumn) values(1) select max(id) as maxid from mytable

Re: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread Dave Watts
> That would ONLY work if you used SET TRANSACTION ISOLATION LEVEL > SERIALIZABLE or WITH(TABLOCKX HOLDLOCK) This is one of those things I never am completely clear on, but I believe that the default isolation level for CFTRANSACTION is serializable in CF 7+. Dave Watts, CTO, Fig Leaf Software h

RE: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread brad
ssage Subject: RE: SQL Gurus... obtaining the correct Incremental ID From: "Che Vilnonis" Date: Wed, April 28, 2010 3:59 pm To: cf-talk I am using the cftransaction tags. Honestly, I was not absolutely sure that I needed to do anything else and that is why I posted my or

RE: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread brad
Gurus... obtaining the correct Incremental ID From: nvc 1 Date: Wed, April 28, 2010 3:14 pm To: cf-talk why can't you do this where mytable has an auto incrementing primary key called id: insert into mytable(acolumn) values(1) select max(id) as maxid from my

RE: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread Che Vilnonis
... obtaining the correct Incremental ID why can't you do this where mytable has an auto incrementing primary key called id: insert into mytable(acolumn) values(1) select max(id) as maxid from mytable ~|

Re: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread nvc 1
why can't you do this where mytable has an auto incrementing primary key called id: insert into mytable(acolumn) values(1) select max(id) as maxid from mytable ~| Want to reach the ColdFusion community with

RE: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread Che Vilnonis
Dave/Barney/Casey... I'm using SQL 2005. I just wanted to cover all bases and was looking for a code snippet. Thanks. -Original Message- From: Casey Dougall [mailto:ca...@uberwebsitesolutions.com] Sent: Wednesday, April 28, 2010 2:13 PM To: cf-talk Subject: Re: SQL Gurus... obta

Re: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread Dave Watts
> Transactions, transactions, transactions. Don't write another line of > SQL until you learn about transactions. I really just want to second this. There should be a law. With penalties including jail time for violation. (But perhaps time off would be granted for understanding indexes.) Dave Wa

Re: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread Casey Dougall
On Wed, Apr 28, 2010 at 1:51 PM, Che Vilnonis wrote: > > When using "set nocount on", "select @@identity as xyz" and "set nocount > off" in a cfquery, how can I be certain that two transactions that occur at > roughly the same time obtain the proper incremental id from an Identity > column? Is t

Re: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread Dave Watts
> When using "set nocount on", "select @@identity as xyz" and "set nocount > off" in a cfquery, how can I be certain that two transactions that occur at > roughly the same time obtain the proper incremental id from an Identity > column? Is their a SQl equivalent to CF's cflock tag? BEGIN TRANSACT

Re: SQL Gurus... obtaining the correct Incremental ID

2010-04-28 Thread Barney Boisvert
Transactions, transactions, transactions. Don't write another line of SQL until you learn about transactions. In this case it doesn't matter because @@identity is bound to the active connection (and connections are single threaded), but you should still be transactionally aware. In addition to