Thursday, July 15, 2021

SQL to count rows of all tables in database

Table ไหน มีข้อมูลเยอะที่สุด? (มีจำนวน row เยอะที่สุด) มันเก็บอยู่ใน sysindexes ใช้คำสั่งต่อไปนี้


SELECT o.NAME, i.rowcnt 

FROM sysindexes AS i

  INNER JOIN sysobjects AS o ON i.id = o.id 

WHERE i.indid < 2  AND OBJECTPROPERTY(o.id, 'IsMSShipped') = 0

ORDER BY o.NAME