SQL count(*) performance

后端 未结 5 1513
自闭症患者
自闭症患者 2020-11-28 06:26

I have a SQL table BookChapters with over 20 millions rows. It has a clustered primary key (bookChapterID) and doesn\'t have any other keys or indexes. It takes miliseconds

5条回答
  •  温柔的废话
    2020-11-28 07:19

    try this, if you need to detect, if the table has more rows than one:

    if (SELECT COUNT(*) FROM (SELECT TOP 2 * FROM BookChapters) AS b) > 1
    

提交回复
热议问题