论坛数据统计           欢迎到【弱电论坛】来学习和讨论问题!

弱电工程项目管理软件
★电工电气产品供求、电气展会、人才、电气技术文章、图库、电气技术论坛等相关内容,请跳转至【电气工程网】--- 可直接使用本站会员名和密码登陆!(首次使用需要激活账户)
标王 热搜: 网络监控  弱电  楼宇对讲  机房及机柜内部的理线方法  门禁  ar800-hn  CAD  综合布线  工资  面板 
 
 
当前位置: 首页 » 技术 » 电脑技术 » 数 据 库 » 正文

清除SQLSERVER数据库日志的方法

放大字体  缩小字体 发布日期:2008-12-22  来源:互联网  作者:manage  浏览次数:736
核心提示:SQLSERVER的数据库日志占用很大的空间,下面提供三种方法用于清除无用的数据库日志文件。 清除SQLSERVER数据库日志文件的方法: 1、先将这个数据库卸载: EXECsp_detach_db’database_name’,’true’ 然后将该数据库所对应的Log文件删掉; 最后,再将这个数据库注册到系
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 

*****转发内容结束*****
 
[ 技术搜索 ]  [ 加入收藏 ]  [ 告诉好友 ]  [ 打印本文 ]  [ 关闭窗口 ]

 
0条 [查看全部]  相关评论

 
点击排行
 
 
 
 
弱电基础 | 常用软件 | 信息发布规则 | 积分规则 | VIP会员注册 | 广告投放 | 弱电培训 | 联系我们 | 版权声明 | 帮助中心 | 网站地图 | 排名推广 | 京ICP备11008917号-3 | RSS订阅
★本站手机app客户端已上线! 点击下载