RE: Insert without checking existance

2011-01-28 Thread Che Vilnonis
Could this be combined with an ELSE statement in SQL? That is, insert if new, update if existing? Thanks, Che -Original Message- This is what I'm using at the moment but I'm going to read what you have as well. I want fast and safe. cfquery datasource=#variables.dsn#

Re: Insert without checking existance

2011-01-28 Thread Michael Dinowitz
Yes. if exists(statement) something else something else The question I have to look up is if the whole operation is one 'unit' or does it have to have transaction control. Is there a 'gap' between the exists() check and the actual sql operation? On Fri, Jan 28, 2011 at 9:15 AM, Che

RE: Insert without checking existance

2011-01-28 Thread Che Vilnonis
, 2011 10:58 AM To: cf-talk Subject: Re: Insert without checking existance Yes. if exists(statement) something else something else The question I have to look up is if the whole operation is one 'unit' or does it have to have transaction control. Is there a 'gap' between the exists() check

Re: Insert without checking existance

2011-01-28 Thread Michael Dinowitz
-Original Message- From: Michael Dinowitz [mailto:mdino...@houseoffusion.com] Sent: Friday, January 28, 2011 10:58 AM To: cf-talk Subject: Re: Insert without checking existance Yes. if exists(statement) something else something else The question I have to look up

Re: Insert without checking existance

2011-01-28 Thread Donnie Carvajal
Is exists() more efficient than this? Yes. I use it all of the time. Exists() will look for until it finds a record and as soon as it finds it, it stops because the criteria is met. A normal Select statement will look at all records and finish once all records have been parsed. It's really

RE: Insert without checking existance

2011-01-28 Thread DURETTE, STEVEN J (ATTASIAIT)
Dinowitz [mailto:mdino...@houseoffusion.com] Sent: Friday, January 28, 2011 11:13 AM To: cf-talk Subject: Re: Insert without checking existance I was doing the @@rowcount version to check then insert but I was unhappy with the performance. I was looking for some something a little better. Still

Re: Insert without checking existance

2011-01-28 Thread Mike Chabot
Yes, there is a small gap between existence checking and the actual insert. Unless you specifically commit the transaction early, all the statements would be in the same transaction. That is true with all the possible methods. Transactions are not the issue. Locking is, but it is only an issue

RE: Insert without checking existance

2011-01-28 Thread DURETTE, STEVEN J (ATTASIAIT)
So just out of curiosity, is this on a SQL 2008 box? If so then you can use merge and give different options for insert or update (even delete if you want) Steve ~| Order the Adobe Coldfusion Anthology now!

Re: Insert without checking existance

2011-01-28 Thread Michael Dinowitz
MSSQL 2000. While this is for a client, a lot of what I'm doing here is going to applied to my own stuff. The client will be moving to MSSQL 2008 soon but I'm assessing if I can stay on MSSQL 2000, can move to MSSQL 2008, or should just move over to MySQL for my own stuff. The licensing on MSSQL

RE: Insert without checking existance

2011-01-28 Thread DURETTE, STEVEN J (ATTASIAIT)
...@houseoffusion.com] Sent: Friday, January 28, 2011 2:13 PM To: cf-talk Subject: Re: Insert without checking existance MSSQL 2000. While this is for a client, a lot of what I'm doing here is going to applied to my own stuff. The client will be moving to MSSQL 2008 soon but I'm assessing if I can

Re: Insert without checking existance

2011-01-27 Thread Michael Grant
I generally prefer validation rather than an expectation of exceptions. What about using the EXISTS? I think this should work if EXISTS (select keyword from table where keyword = '#keyword#') -- do nothing ELSE -- do insert On Thu, Jan 27, 2011 at 6:06 PM, Michael Dinowitz

Re: Insert without checking existance

2011-01-27 Thread Michael Dinowitz
Is exists() more efficient than this? SET NOCOUNT ON Select keywordid from keywords where keyword =@keyword if @@ROWCOUNT 1 begin Insert into keywords(keyword) values(@keyword) end SET NOCOUNT OFF I'm using a stored procedure for the tiny performance savings I may get. On Thu, Jan 27,

Re: Insert without checking existance

2011-01-27 Thread Michael Grant
Is exists() more efficient than this? That I don't know. I suspect it is, and that it's pretty nominal. ~| Order the Adobe Coldfusion Anthology now!

Re: Insert without checking existance

2011-01-27 Thread Mike Chabot
There are a number of ways to solve this issue. The solution Michael Grant recommended is a good one and is probably the most common approach. The test for existence should be slightly faster than getting the exact row count, although the speed difference is likely unnoticeable. Assumption:

Re: Insert without checking existance

2011-01-27 Thread Steve Bryant
Michael, I typically use a SELECT INTO with a NOT EXISTS clause. That keeps the entire thing in one tight query. http://www.bryantwebconsulting.com/blog/index.cfm/2005/3/16/prevent_duplicate_inserts See also the link in the comments for a more fail-safe method (though specific to SQL

Re: Insert without checking existance

2011-01-27 Thread Michael Dinowitz
This is what I'm using at the moment but I'm going to read what you have as well. I want fast and safe. Thanks cfquery datasource=#variables.dsn# if not exists( Select keywordid from keywords where keyword =