任何人都可以帮我从包含以下列的数据库中获取表信息:
我有50个数据库,我希望在excel文件中传输此信息
答案 0 :(得分:0)
此查询将为您提供在SQL Server中查找的结果。
SELECT
DB_NAME() AS DatabaseName,
t.NAME AS TableName,
t.max_column_id_used AS Columns,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM
sys.tables t
INNER JOIN
sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN
sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN
sys.allocation_units a ON p.partition_id = a.container_id
WHERE
t.NAME NOT LIKE 'dt%'
AND t.is_ms_shipped = 0
AND i.OBJECT_ID > 255
GROUP BY
t.Name, t.max_column_id_used
ORDER BY
t.Name
如果您需要传输所有这些信息并将其存储在Excel电子表格中,那么您需要创建一个SSIS包,其中包含 -
如果您在创建SSIS包时遇到挑战,则可以针对每个数据库手动执行此查询,并将结果复制/粘贴到Excel中。心灵麻木无聊,但一次性活动。