但是如何得到某個數據庫所有的表的記錄數,你要是用上面的方法估計得累死了。呵呵
下面提供如何借用sysindexes和sysobjects表來得到某個數據庫每個表記錄數的方法:
先給出SQL Server 2000版本的:
復制代碼 代碼如下:
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
SQL Server2005/8版本的SQL 語句:
復制代碼 代碼如下:
SELECT o.name,
ddps.row_count
FROM sys.indexes AS i
INNER JOIN sys.objects AS o ON i.OBJECT_ID = o.OBJECT_ID
INNER JOIN sys.dm_db_partition_stats AS ddps ON i.OBJECT_ID = ddps.OBJECT_ID
AND i.index_id = ddps.index_id
WHERE i.index_id < 2
AND o.is_ms_shipped = 0
ORDER BY o.NAME
趕快試試吧,肯定和你count(*)得到的結果相同。