Hi,
Assuming that you use the auto statistics create & open and have all the statistics updated well, i think that it will be better to read from the statistics and not performing a real counting of the rows which is a litle bit physically i would say.
See my code and try it for huge tables and see the difference in time and I/O's.
ALTER function [dbo].[fn_UTL_GetRowCount]
(
@TableNamesysname = null
)
returns bigint
as
begin
-- Example:
-- select dbo.fn_UTL_GetRowCount ('tblAccounts')
-- select top 10 name, dbo.fn_UTL_GetRowCount (name) fromsys.tables
declare@outbigint
select@out = i.rowcnt
fromsys.sysindexes i
whereid = object_id(@TableName)
and(i.indid = 0 or i.indid = 1)
return@out
end