Path: dp-news.maxwell.syr.edu!spool.maxwell.syr.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.vmunix.org!newsfeed.cw.net!cw.net!news-FFM2.ecrc.de!peer-uk.news.demon.net!kibo.news.demon.net!mutlu.news.demon.net!news.demon.co.uk!demon!not-for-mail
From: "Tony Rogerson" <tonyrogerson@sqlserverfaq.com>
Newsgroups: comp.databases.theory
Subject: Re: counting rows
Date: Fri, 31 Mar 2006 08:46:20 +0100
Lines: 25
Message-ID: <e0imo5$312$1$8302bc10@news.demon.co.uk>
References: <1143753100.408985.38260@u72g2000cwu.googlegroups.com>
NNTP-Posting-Host: torver-adsl.demon.co.uk
X-Trace: news.demon.co.uk 1143791173 3106 80.177.180.177 (31 Mar 2006 07:46:13 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Fri, 31 Mar 2006 07:46:13 +0000 (UTC)
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
X-Priority: 3
X-RFC2646: Format=Flowed; Original
X-Newsreader: Microsoft Outlook Express 6.00.3790.1830
X-MSMail-Priority: Normal
Xref: dp-news.maxwell.syr.edu comp.databases.theory:37701

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@gmail.com> wrote in message 
news:1143753100.408985.38260@u72g2000cwu.googlegroups.com...
> 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
> 


