If you are just doing an insert, why don't you do it like this Insert into table(keyword) Select @keyword -- Variable containing the keyword Where not exists(select keyword from table where keyword=@keyword);
Keeps it all in one block/transaction. -----Original Message----- From: Michael 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 not happy. I've got a keywords table with 2 columns - an ID (int) and a keyword (varchar). With an index on keyword, it should be very quick to do the check/insert operation. On Fri, Jan 28, 2011 at 11:02 AM, Che Vilnonis <ch...@asitv.com> wrote: > > Michael, I found this using Google... > > UPDATE Table1 > SET (...) > WHERE Column1='SomeValue' > > IF @@ROWCOUNT=0 > > INSERT INTO Table1 > VALUES (...) > > Might be better? Che > > -----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 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? > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:341636 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm