如何在 SQL Server 中查找没有记录的表列表 [英] How to find list of tables having no records in SQL server

查看:76
本文介绍了如何在 SQL Server 中查找没有记录的表列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何显示其中没有记录并且它们存在于sql server数据库中的表的列表.只需要显示其中没有记录的表.

How to display a list of tables having no record in them and they are existing in the sql server database.Required is only to show tables with no record in them.

推荐答案

试试这个:

SELECT 
    t.NAME AS TableName,
    p.rows AS RowCounts
FROM 
    sys.tables t
INNER JOIN 
    sys.partitions p ON t.object_id = p.OBJECT_ID 
WHERE 
    t.NAME NOT LIKE 'dt%' 
    AND t.is_ms_shipped = 0
    AND p.rows = 0
GROUP BY 
    t.Name, p.Rows
ORDER BY 
    t.Name

查询转到 sys.tables 和其他目录视图以查找表、它们的索引和分区,以查找那些行数为 0 的表.

The query goes to the sys.tables and other catalog views to find the tables, their indexes and partitions, to find those tables that have a row count of 0.

这篇关于如何在 SQL Server 中查找没有记录的表列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆