清除SQLSERVER數據庫日志的方法

發表于:2012-09-28來源:月光博客作者:不詳點擊數: 標簽:SQLServer
SQLSERVER的數據庫日志占用很大的空間,下面提供三種方法用于清除無用的數據庫日志文件。 清除SQLSERVER數據庫日志文件的方法: 1、先將這個數據庫卸載: EXEC sp_detach_db 'database_name', 'true'

  SQLSERVER的數據庫日志占用很大的空間,下面提供三種方法用于清除無用的數據庫日志文件。

  清除SQLSERVER數據庫日志文件的方法:

  1、先將這個數據庫卸載:

  EXEC sp_detach_db 'database_name', 'true'

  然后將該數據庫所對應的Log文件刪掉;

  最后,再將這個數據庫注冊到系統里面:

  EXEC sp_attach_db @dbname = N'database_name',

  @filename1 = N'e:\mssql7\data\database_name_data.mdf'

  2、數據庫上點右鍵-所有任務-收縮數據庫-選擇收縮文件為LOG 。

  3、清除SQLSERVER數據庫日志的方法:

  *******下面是轉發的郵件*****

  The shrinking of log files is not immediate in SQL Server 7.0. The

  shrinking of log files does not occur until the active portion of the

  log moves. As updates are performed on the database, the shrink

  operation occurs at checkpoints or transaction log backups. Each log

  file is marked with the target_percent for the shrink operation. Each

  subsequent log backup or log truncation attempts to shrink the file to

  bring its size as close to the target_percent as possible. Because a log

  file can be shrunk only to a virtual log file boundary, it may not be

  possible to shrink a log file to a size smaller than the size of a

  virtual log file even if it is not being used. Please refer to SQL Book

  Online for the details.

  RESOLUTION

  Below script will help to shrink the log file immediately, pls keep it

  running for 3~4 minutes and then stop it manually.

  \* Run "select fileid, name,filename from ..sysfiles" to get

  the fileid which you want to shrink *\

  use

  go

  dbcc shrinkfile(fileid,notruncate)

  dbcc shrinkfile(fileid,truncateonly)

  create table t1 (char1 char(4000))

  go

  declare @i int

  select @i = 0

  while (1 = 1)

  begin

  while (@i < 100)

  begin

  insert into t1 values ('a') select @i = @i +1

  end

  truncate table t1

  backup log with truncate_only

  end

  go

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97