SQL小技巧 又快又简单的得到你的数据库每个表的记录数
程序员文章站
2023-12-10 20:09:58
但是如何得到某个数据库所有的表的记录数,你要是用上面的方法估计得累死了。呵呵 下面提供如何借用sysindexes和sysobjects表来得到某个数据库每个表记录数的方法...
但是如何得到某个数据库所有的表的记录数,你要是用上面的方法估计得累死了。呵呵
下面提供如何借用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(*)得到的结果相同。
下面提供如何借用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(*)得到的结果相同。