Sqlserver 查看表空间,收缩数据库日志

SELECT
t.NAME AS 表名,
p.rows AS 行数,
SUM(a.total_pages) * 8 / 1024 AS 总空间MB,
SUM(a.used_pages) * 8 / 1024 AS 已用空间MB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 / 1024 AS 未用空间MB
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, p.Rows
ORDER BY
总空间MB DESC;


Sqlserver 查看表空间,收缩数据库日志_第1张图片

**

收缩数据库日志文件 第一步,设置数据库恢复简单模式 第二步,开启自动收缩

**
Sqlserver 查看表空间,收缩数据库日志_第2张图片
第三步开始手动收缩
Sqlserver 查看表空间,收缩数据库日志_第3张图片
**

结束。 200G的文件,直接缩完了。

**

你可能感兴趣的:(数据库,sqlserver)