SQLSERVER中统计所有表的记录数

利用系统索引表sysindexes中索引ID indid<1的行中的rows列存有该表的行数这一特点.    方法是利用隐藏未公开的系统存储过程sp_MSforeachtable

CREATE TABLE #temp (TableName VARCHAR (255), RowCnt INT)
EXEC sp_MSforeachtable 'INSERT INTO #temp SELECT ''?'', COUNT(*) FROM ?'
SELECT TableName, RowCnt FROM #temp ORDER BY RowCnt DESC
DROP TABLE #temp

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2022-01-06
  • 2021-06-25
  • 2021-06-03
  • 2022-01-12
  • 2021-09-23
猜你喜欢
  • 2021-09-07
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
  • 2021-09-17
相关资源
相似解决方案