tags:

views:

170

answers:

2

I am wondering which is a more efficent method to retrieve data from the database.

ex. One particular part of my application can have well over 100 objects. Right now I have it setup to query the database twice for each object. This part of the application periodically refreshes itself, say every 2 minutes, and this application will probably end of being installed on 25-30 pc's. I am thinking that this is a large number of select statements to make from the database, and I am thinking about trying to optimize the procedure. I have to pull the information out of several tables, and both queries are using join statements.

Would it be better to rewrite the queries so that I am only executing the queries twice per update instead of 200 times? For example using a large where statement to include each object, and then do the processing of the data outside of the object, rather than inside each object?

Using SQL Server, .net No indexes on the tables, size of database is less than 10-5th

+3  A: 

all things being equal, many statements with few rows is usually worse than few statements with many rows.

show the actual code and get better answers.

KM
Thats what just what I was looking for. Thanks
Aaron M
the overhead of running the query N times for 1 row is worse than running it 1 time and returning N rows
KM
I'm uncomfortable with this already being an accepted answer. Who knows what his use case is. I don't trust the OP with taking this nougat (as accurate as it may be) and running with it.
Mark Canlas
+1  A: 

The default answer for optimization must always be: don't optimize until you have a demonstrated need for it. The followup is: once you have a demonstrated need for it, and an alternative approach: try both ways to determine which is faster. You can't predict which will be faster, and we certainly can't. KM's answer is good - fewer queries tends to be better - but the way to know is to test.

Carl Manaster