SQL小技巧 又快又简单的得到你的数据库每个表的记录数

前端之家收集整理的这篇文章主要介绍了SQL小技巧 又快又简单的得到你的数据库每个表的记录数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

但是如何得到某个数据库所有的表的记录数,你要是用上面的方法估计得累死了。呵呵
下面提供如何借用sysindexes和sysobjects表来得到某个数据库每个表记录数的方法:
先给出sql Server 2000版本的:
<div class="codetitle"><a style="CURSOR: pointer" data="94431" class="copybut" id="copybut94431" onclick="doCopy('code94431')"> 代码如下:

<div class="codebody" id="code94431">
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 语句:
<div class="codetitle"><a style="CURSOR: pointer" data="86145" class="copybut" id="copybut86145" onclick="doCopy('code86145')"> 代码如下:
<div class="codebody" id="code86145">
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(*)得到的结果相同。

原文链接:https://www.f2er.com/mssql/64292.html

猜你在找的MsSQL相关文章