select rowcnt from sys.sysindexes where id=object_id('orders') and indid=1
--计算一个库里各个表的记录总数: select b.name,a.rowcnt from sysindexes a,sysobjects b where a.id=b.id and a.indid<2 and b.xtype='u'
SELECT SUM (row_count) AS total_number_of_rows FROM sys.dm_db_partition_stats where object_id=object_id('HumanResources.EmployeeAddress') AND (index_id=0 or index_id=1);
最好不要用sysindexes 。下面的msdn的提示
重要提示:
将此 SQL Server 2000 系统表作为一个视图包含进来是为了保持向后兼容性。建议您改用当前的 SQL Server 系统视图。若要查找一个或多个等效系统视图,请参阅将 SQL Server 2000 系统表映射到 SQL Server 2005 系统视图。后续版本的 Microsoft SQL Server 将删除该功能。请避免在新的开发工作中使用该功能,并着手修改当前还在使用该功能的应用程序。
可以用
select rows from sys.partitions where object_id = object_id('Order') and index_id = 1