Re: counting rows
From: Tony Rogerson <tonyrogerson_at_sqlserverfaq.com>
Date: Fri, 31 Mar 2006 08:46:20 +0100
Message-ID: <e0imo5$312$1$8302bc10_at_news.demon.co.uk>
Date: Fri, 31 Mar 2006 08:46:20 +0100
Message-ID: <e0imo5$312$1$8302bc10_at_news.demon.co.uk>
Number 2 will be best because you are effectively storing the aggregate instead of the server having to count the number of rows in the table which would require IO.
Tony.
-- Tony Rogerson SQL Server MVP http://sqlserverfaq.com - free video tutorials <bucaliman_at_gmail.com> wrote in message news:1143753100.408985.38260_at_u72g2000cwu.googlegroups.com...Received on Fri Mar 31 2006 - 09:46:20 CEST
> Consider the tables USERS and PICTURES. When retrieving the number of
> pictures from a user there are two ways:
>
> 1) I count them from pictures table.
> 2) I pick it directly from a field "numPictures" in table users.
>
> How are you used to do this? Which is better?
> Thanks
>