如何显示没有插入记录的表列表,它们存在于sql server database中。只查看表中没有记录的表。
答案 0 :(得分:21)
试试这个:
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的表。
答案 1 :(得分:3)
更改架构名称:
SELECT
sch.name,
t.NAME AS TableName,
p.rows AS RowCounts
FROM
sys.tables t
INNER JOIN
sys.partitions p ON t.object_id = p.OBJECT_ID
inner Join sys.schemas sch
on t.schema_id = sch.schema_id
WHERE
t.NAME NOT LIKE 'dt%'
AND t.is_ms_shipped = 0
AND p.rows = 0
GROUP BY
sch.name,t.Name, p.Rows
ORDER BY
sch.name,t.Name