Posts
834
Comments
697
Trackbacks
1
How to get a rowcount in T-SQL without using Count(*)

From:

SQL Server Books Online (BOL) documents the structure of sysindexes; the value of sysindexes.indid will always be 0 for a table and 1 for a clustered index. If a table doesn't have a clustered index, its entry in sysindexes will always have an indid value of 0. If a table does have a clustered index, its entry in sysindexes will always have an indid value of 1.
 

SELECT object_name(id) as tablename ,rowcnt
FROM sysindexes
WHERE indid IN (1,0) AND OBJECTPROPERTY(id, 'IsUserTable') = 1
order by tablename

posted on Friday, February 04, 2005 8:54 AM
Comments
Gravatar
# re: How to get a rowcount in T-SQL without using Count(*)
Steve
3/11/2008 12:00 PM
select count(distinct idField) from EmployeeTable

If you have a primary key field.

Unless of course you mean without using the Count function.

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 4 and 7 and type the answer here: