PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.

Which is more expensive?

 
 
Mike
Guest
Posts: n/a
 
      4th Feb 2008
Which is more expensive? Trapping an Exception to prevent duplicate entries
in a database, or using IF EXISTS in T-SQL?

Also, how would I go about testing which is more expensive myself?

Thanks




 
Reply With Quote
 
 
 
 
Michael O
Guest
Posts: n/a
 
      4th Feb 2008
On Feb 4, 2:23 pm, "Mike" <bl...@blank.com> wrote:
> Which is more expensive? Trapping an Exception to prevent duplicate entries
> in a database, or using IF EXISTS in T-SQL?
>
> Also, how would I go about testing which is more expensive myself?
>
> Thanks


For a single insert in your stored procedure when IF EXISTS is true
and/or an index violation is thrown, I don't know.

But if you are talking across the breadth of many rows, each with
their own invocation of your stored procedure - and there were few to
no duplicates then it would definitely be slower to test before
inserting. Only you know how often the circumstance of duplication is
likely to occur. Write two sets of test code that reflects your
assumption on quantity and quality of data - one that uses TRY and the
other IF EXISTS - and then keep a close look at your watch.

Michael O
http:/blog.crisatunity.com
 
Reply With Quote
 
 
 
 
Mike
Guest
Posts: n/a
 
      5th Feb 2008

"Michael O" <(E-Mail Removed)> wrote in message
news:c8e32dda-14ee-4ed4-8ce7-(E-Mail Removed)...
> On Feb 4, 2:23 pm, "Mike" <bl...@blank.com> wrote:
>> Which is more expensive? Trapping an Exception to prevent duplicate
>> entries
>> in a database, or using IF EXISTS in T-SQL?
>>
>> Also, how would I go about testing which is more expensive myself?
>>
>> Thanks

>
> For a single insert in your stored procedure when IF EXISTS is true
> and/or an index violation is thrown, I don't know.
>
> But if you are talking across the breadth of many rows, each with
> their own invocation of your stored procedure - and there were few to
> no duplicates then it would definitely be slower to test before
> inserting. Only you know how often the circumstance of duplication is
> likely to occur. Write two sets of test code that reflects your
> assumption on quantity and quality of data - one that uses TRY and the
> other IF EXISTS - and then keep a close look at your watch.
>
> Michael O
> http:/blog.crisatunity.com


I should have been clearer. I was wanting to compare Try... Catch... in the
database method code, such as in an ASP.NET app, with IF EXISTS in T-SQL.
So the location of the code is different for either case.



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
USB TO RS232 ..more than one in pc ? how to know which is which ? Graham Windows XP General 3 3rd Jan 2010 06:39 PM
Which mobo? which CPU? which RAM? Is the new system worth it??? padiq75@googlemail.com DIY PC 5 5th Jul 2007 01:05 AM
More and More and More often random PCs wont load a page. todd.roat@uc.edu Windows XP Internet Explorer 0 13th Jul 2006 03:23 PM
More and More page loading issues: usual IE woes and more =?Utf-8?B?QSBHdW5zbGluZ2Vy?= Windows XP Internet Explorer 2 9th Mar 2006 11:07 PM
Temp Files - More & More & More of them??? Stew Spyware Discussion 6 28th Sep 2005 05:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:13 PM.