By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,625 Members | 1,636 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,625 IT Pros & Developers. It's quick & easy.

Multiple Queries vs Dataset

P: 34
Hello all.

I was wondering if there is much of a performance difference between multiple DB queries, which return a single datatable, vs a single query that returns multiple datatables.


Expand|Select|Wrap|Line Numbers
  1. DataTable dt1 = "SELECT * FROM tbl"
  2. DataTable dt2 = "SELECT * FROM tbl2"
  3. DataTable dt3 = "SELECT * FROM tbl3"

Expand|Select|Wrap|Line Numbers
  1. DataSet ds1 = "SELECT * FROM tbl; SELECT * FROM tbl2; SELECT * FROM tbl3"
Feb 20 '08 #1
Share this Question
Share on Google+
3 Replies

Expert 2.5K+
P: 2,878
A semicolon is a Transact-SQL statement terminator. So either you split it in different run or run it with statement separator, it will still run it sequentially. However, the latter, I think (read: not sure), it will only return the result of your last SELECT

-- CK
Feb 20 '08 #2

P: 34
Correct, but my question centred more around that one method only required one connection to the db to perform multiple queries; but it also meant that it was bringing back a bigger result set.

So the question, really, is the time it takes to transform those multiple result sets into a datatable faster than using the mutiple db connections needed if they were returned as single result sets?
Feb 21 '08 #3

Expert 2.5K+
P: 2,878
In theory, the multiple connection will take some time than a single connection. Since, the connection has to be established by your Dataset. It would depend, also on how you connect to your db from your Apps. I am also not sure which recordset will your query return, since sql-server will treat that as 3 query and will execute it one after the other, but I am assuming you're trying to execute a multiple t-sql and not just select. If you need all those returned, you might need a UNION and you just need to use a single connection.

Did I even make sense? :)

-- CK
Feb 22 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.