获取数据库中所有表的行数:SQL Server

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22548938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 01:25:57  来源:igfitidea点击:

Get row count of all tables in database: SQL Server

sqlsql-server

提问by Charles M

I'm trying to familiarize myself with a large database and search for relevant information among the many tables. I often find myself calling up a table, to see if there is relevant data inside, only to find that the table has no records.

我试图让自己熟悉一个大型数据库并在许多表中搜索相关信息。经常发现自己在调一张表,看里面有没有相关数据,却发现该表没有记录。

How to quickly call up a list of all tables and the number of records contained therein? I'm using sql server 2008.

如何快速调出所有表的列表以及其中包含的记录数?我正在使用 sql server 2008。

Thanks!

谢谢!

Related Question: How do I QUICKLY check many sql database tables and views to see if they are not empty or contain records

相关问题:如何快速检查多个sql数据库表和视图是否为空或包含记录

回答by Mitch Wheat

Right click on database -> Reports -> Standard Reports -> Disk usage by Top Tables

右键单击数据库 -> 报告 -> 标准报告 -> 顶级表的磁盘使用情况

enter image description here

在此处输入图片说明

回答by Szymon

If you want to use a query, you can use this (note: it's using an undocumented stored procedure sp_msforeachtable):

如果你想使用查询,你可以使用这个(注意:它使用的是一个未记录的存储过程sp_msforeachtable):

create table #tempcount (tablename nvarchar(128), record_count bigint)
EXEC sp_msforeachtable 'insert #tempcount select ''?'', count(*) from ? with (nolock)'
select * from #tempcount
drop table #tempcount