The story is that I need to optimize my database access.
Now I need to retrieve related data from like 6 different tables. and I’ve summerized the people’s advise in those points:
-
Using the same connection for
different commands still pays a
visit to the db with every command
execution -
Stored procedures are a good way to
have more than select statement
(without using joins) to select from more than one table and paying only a single visit to the database -
The source of the real load on the database is the connection to it, not the quantity of the data (quantity still affects the performance but N connections is a bigger factor).
Now I want to have multiple SELECT statements and as advised and more the points above I think I should go with the Stored Procedure option. but I got the thought to use batch SELECT statements instead
Example: SELECT e FROM p; SELECT x,y,z FROM t; SELECT ....; SELECT ....;
Will this cause in a single trip to the database as the stored procedure or not ?
and what do you think about my options ?
..Thanks for your time in advance 🙂
To answer your question: the only difference is that you’re transferring the whole query instead of just the stored proc name to the database server. Unless your query is a few MBs long or is executed a few thousand times per second, it shouldn’t make any difference in terms of performance.