SQL: better than select count(*)
If you need to count all rows from a table without any conditional, there's a much better and faster way than select count(*). This code works with Microsoft SQL 2000 and 2005.
RETURNS INT
AS
BEGIN
DECLARE @Rows int
SELECT @Rows = rows
FROM sysindexes
WHERE id = OBJECT_ID(@Table)
AND indid < 2
RETURN @Rows
END
p.s. I've been using this code for so long, I don't even remember who to give credit to :) thanks!
http://www.robgonda.com/blog/trackback.cfm?86BF42A4-3048-7431-E492C327D2F8A6C4
There are no comments for this entry.
[Add Comment]