I need to determine the number of rows of a temp table in SQL Server. The obvious way to do it is
select count(*) from #table
The problem is that if the #table is huge, count(*) takes too long.
I am aware that one can find the number of rows of a table this way:
select so.name,
case when si.indid between 1 and 254
then si.[name] else NULL end AS [Index Name],
si.indid,
rows as number_of_rows
from sys.sysindexes si
inner join sys.sysobjects so on si.id = so.id
and si.indid < 2
and so.type = 'U'
and so.name <> 'dtproperties'
where so.name = 'table_name'
Is there any similar query that works for a temp table?
Another way I was thinking of:
Select Top 1 rn From
(Select *, ROW_NUMBER() Over (Order by (Select NULL) ) As rn From geschaeft.SPOTGeschaeftstammMonat ) As a
Order by rn Desc
Any ideas?