-- DON'T FORGET TO BACKUP THE DB :D (Check [here][1])
USE AdventureWorks2008R2;
GO
-- Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE AdventureWorks2008R2
SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (AdventureWorks2008R2_Log, 1);
GO
-- Reset the database recovery model.
ALTER DATABASE AdventureWorks2008R2
SET RECOVERY FULL;
GO
USE DATABASE_NAME;
GO
ALTER DATABASE DATABASE_NAME
SET RECOVERY SIMPLE;
GO
--First parameter is log file name and second is size in MB
DBCC SHRINKFILE (DATABASE_NAME_Log, 1);
ALTER DATABASE DATABASE_NAME
SET RECOVERY FULL;
GO
你能做些什么来减少这种情况?
实际上,日志文件是SQL服务器在事务发生时保存的文件数据。对于要处理的事务,SQL服务器为其分配页面。但在交易完成后,它们不会突然被释放,希望可能会有类似的交易到来。这撑起了空间。< / p >
< p >步骤1:
首先在已探索的数据库查询中运行此命令
检查点< / p >
< p >步骤2:
右键单击数据库
任务>备份
选择备份类型为事务日志
增加备份数据(.bak)的目的地址和文件名
alter database <database_name> set emergency;
use <database_name>;
checkpoint;
checkpoint;
alter database <database_name> set online;
dbcc shrinkfile(<database_name>_log, 200);