Application executes complex SQL query

My application needs to execute a rather complex series of database queries. I usually just dump everything into a stored procedure and execute it that way.

But I don't have access to the database I am trying to access, so I cannot create the stored procedure. Is there a better way to do this rather than hitting the database 5-6 times to get the results I want? I could combine everything into one query, but I would like to avoid this if possible, since I would need to combine about 10 tables.

+1


source to share


3 answers


There is nothing wrong with joining 10 tables if that is ultimately what you need to do. In general, SQL is good at this. However, if there is no such connection between your 5-6 requests, run them separately.



If you choose to split the query, hitting DB 5-6 times is fine - absolutely nothing wrong with that. Your accessor (e.g. ADO.NET) probably gives you connection pooling anyway, so the overhead of multiple requests is very small.

+5


source


You can always execute the same series of requests in one shot by dividing them with ";",



+1


source


If it is possible to combine everything into one query, then in my experience it is almost always more efficient for this; you have to do it independently. Follow this trail first anyway. Consider only alternatives if this is not possible.

0


source







All Articles