How do I use ROW_NUMBER()?

前端 未结 13 2415
青春惊慌失措
青春惊慌失措 2020-11-28 02:35

I want to use the ROW_NUMBER() to get...

  1. To get the max(ROW_NUMBER()) --> Or i guess this would also be the count of all rows
13条回答
  •  执笔经年
    2020-11-28 03:09

    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.

提交回复
热议问题