每次看到暴涨的数据库日志就有些头大,于是乱搜一通找个办法把日志干掉,下次又头大,又搜半天,于是还是写篇blog,不用乱找了。
1.将数据库设置成 简单 模式
选择要收缩的数据库,点右键 属性->选项,选择 简单模式
2.选择任务->收缩->文件
3.选择日志
或者用如下语句
代码
USE [master]
GO
ALTER DATABASE DNName SET RECOVERY SIMPLE WITH NO_WAIT
GO
ALTER DATABASE DNName SET RECOVERY SIMPLE
GO
USE DNName
GO
DBCC SHRINKFILE (N'LogFileName' , 0,TRUNCATEONLY)
GO
USE [master]
GO
ALTER DATABASE DNName SET RECOVERY FULL WITH NO_WAIT
GO
ALTER DATABASE DNName SET RECOVERY FULL
GO
GO
ALTER DATABASE DNName SET RECOVERY SIMPLE WITH NO_WAIT
GO
ALTER DATABASE DNName SET RECOVERY SIMPLE
GO
USE DNName
GO
DBCC SHRINKFILE (N'LogFileName' , 0,TRUNCATEONLY)
GO
USE [master]
GO
ALTER DATABASE DNName SET RECOVERY FULL WITH NO_WAIT
GO
ALTER DATABASE DNName SET RECOVERY FULL
GO
LogFileName获取sql语句:
SELECT NAME, size FROM sys.database_files