压缩sql server 数据库的空间,清理日志.ldf
作者:互联网
--查询LogDB使用空间
use LogDB
SELECT Name,
physical_name,
Size/128.0 AS [Size(MB)],
FILEPROPERTY(Name,'SpaceUsed')/128.0 AS [SpaceUsed(MB)],
STR(FILEPROPERTY(Name,'SpaceUsed')*1.0/Size*100,6,3) AS [SpaceUsed(%)]
FROM sys.database_files
--压缩LogDB库的空间
DBCC SHRINKDATABASE('LogDB')
--清理LogDB库的日志.ldf
USE [master]
GO
ALTER DATABASE LogDB SET RECOVERY SIMPLE WITH NO_WAIT
GO
ALTER DATABASE LogDB SET RECOVERY SIMPLE --简单模式
GO
USE LogDB
GO
DBCC SHRINKFILE (N'LogDB_log' , 2, TRUNCATEONLY) --设置压缩后的日志大小为2M,可以自行指定
GO
USE [master]
GO
ALTER DATABASE LogDB SET RECOVERY FULL WITH NO_WAIT
GO
ALTER DATABASE LogDB SET RECOVERY FULL --还原为完全模式
GO
标签:SET,ldf,DATABASE,--,server,sql,RECOVERY,SpaceUsed,LogDB 来源: https://www.cnblogs.com/amusement1992/p/15922684.html