--查询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