I want to use the ROW_NUMBER()
to get...
max(ROW_NUMBER())
--> Or i guess this would also be the count of all rows
If you need to return the table's total row count, you can use an alternative way to the SELECT COUNT(*)
statement.
Because SELECT COUNT(*)
makes a full table scan to return the row count, it can take very long time for a large table. You can use the sysindexes
system table instead in this case. There is a ROWS
column that contains the total row count for each table in your database. You can use the following select statement:
SELECT rows FROM sysindexes WHERE id = OBJECT_ID('table_name') AND indid < 2
This will drastically reduce the time your query takes.