代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
MSSQL
】
清理日志
作者:
Dezai.CN
/ 发布于
2011/8/9
/
751
<div> <div><span style="color: rgb(0,0,255)">use</span><span style="color: rgb(0,0,0)"> CTC315 </span><span style="color: rgb(0,0,255)">select</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,128,128)">*</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">from</span><span style="color: rgb(0,0,0)"> sysfiles </span><span style="color: rgb(0,0,255)">dump</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">transaction</span><span style="color: rgb(0,0,0)"> CTC315 </span><span style="color: rgb(0,0,255)">with</span><span style="color: rgb(0,0,0)"> no_log </span><span style="color: rgb(0,0,255)">DBCC</span><span style="color: rgb(0,0,0)"> SHRINKFILE (</span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(255,0,0)">CTC315_Log</span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(0,0,0)">) </span><span style="color: rgb(0,0,255)">set</span><span style="color: rgb(0,0,0)"> ANSI_NULLS </span><span style="color: rgb(0,0,255)">ON</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">set</span><span style="color: rgb(0,0,0)"> QUOTED_IDENTIFIER </span><span style="color: rgb(0,0,255)">ON</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">go</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">create</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">procedure</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(255,0,0)">[</span><span style="color: rgb(255,0,0)">dbo</span><span style="color: rgb(255,0,0)">]</span><span style="color: rgb(0,0,0)">.</span><span style="color: rgb(255,0,0)">[</span><span style="color: rgb(255,0,0)">p清除日志</span><span style="color: rgb(255,0,0)">]</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,128,0)">@databasename</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">varchar</span><span style="color: rgb(0,0,0)">(</span><span style="color: rgb(128,0,0); font-weight: bold">100</span><span style="color: rgb(0,0,0)">) </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)"> 数据库名称</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,255)">as</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">begin</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">declare</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,128,0)">@execsql</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">nvarchar</span><span style="color: rgb(0,0,0)">(</span><span style="color: rgb(255,0,255)">max</span><span style="color: rgb(0,0,0)">), </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)"> 执行语句</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,128,0)">@logfilename</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">varchar</span><span style="color: rgb(0,0,0)">(</span><span style="color: rgb(128,0,0); font-weight: bold">100</span><span style="color: rgb(0,0,0)">) </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)"> 日志逻辑文件</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,255)">select</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,128,0)">@execsql</span><span style="color: rgb(128,128,128)">=</span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(255,0,0)">select @filename=name from </span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(128,128,128)">+</span><span style="color: rgb(0,128,0)">@databasename</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,128,128)">+</span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(255,0,0)">.dbo.[sysfiles] where fileid=2</span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)"> 查询文件名</span><span style="color: rgb(0,128,128)"> --</span><span style="color: rgb(0,128,128)"> select 1,@execsql,@logfilename </span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,255)">exec</span><span style="color: rgb(0,0,0)"> sp_executesql </span><span style="color: rgb(0,128,0)">@execsql</span><span style="color: rgb(0,0,0)">,N</span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(255,0,0)">@filename varchar(100) output </span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(0,0,0)">,</span><span style="color: rgb(0,128,0)">@logfilename</span><span style="color: rgb(0,0,0)"> output </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)"> select 1,@logfilename</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,255)">select</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,128,0)">@execsql</span><span style="color: rgb(128,128,128)">=</span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(255,0,0)">use </span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(128,128,128)">+</span><span style="color: rgb(0,128,0)">@databasename</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,128,128)">+</span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(255,0,0)"> dump transaction </span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(128,128,128)">+</span><span style="color: rgb(0,128,0)">@databasename</span><span style="color: rgb(128,128,128)">+</span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(255,0,0)"> with no_log </span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,128,128)">+</span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(255,0,0)"> DBCC SHRINKFILE (</span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(128,128,128)">+</span><span style="color: rgb(0,128,0)">@logfilename</span><span style="color: rgb(128,128,128)">+</span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(255,0,0)">) </span><span style="color: rgb(255,0,0)">'</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)"> 清除脚本</span><span style="color: rgb(0,128,128)"> --</span><span style="color: rgb(0,128,128)"> select @execsql</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,255)">exec</span><span style="color: rgb(0,0,0)"> sp_executesql </span><span style="color: rgb(0,128,0)">@execsql</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)"> 清除</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">end</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,128,128)">/*</span><span style="color: rgb(0,128,128)"> exec [p清除日志] 'master' </span><span style="color: rgb(0,128,128)">*/</span></div> <div class="cnblogs_code"> <div><span style="color: rgb(0,0,0)">SQL </span><span style="color: rgb(128,0,0); font-weight: bold">7.0</span><span style="color: rgb(128,128,128)">/</span><span style="color: rgb(128,0,0); font-weight: bold">2000</span><span style="color: rgb(0,0,0)">: </span><span style="color: rgb(0,0,255)">BACKUP</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">TRANSACTION</span><span style="color: rgb(0,0,0)"> DBName </span><span style="color: rgb(0,0,255)">WITH</span><span style="color: rgb(0,0,0)"> TRUNCATE_ONLY </span><span style="color: rgb(0,0,255)">DBCC</span><span style="color: rgb(0,0,0)"> SHRINKFILE(</span><span style="color: rgb(128,0,0); font-weight: bold">2</span><span style="color: rgb(0,0,0)">,</span><span style="color: rgb(128,0,0); font-weight: bold">200</span><span style="color: rgb(0,0,0)">) SQL </span><span style="color: rgb(128,0,0); font-weight: bold">2005</span><span style="color: rgb(0,0,0)">: 在 SQL </span><span style="color: rgb(128,0,0); font-weight: bold">2005</span><span style="color: rgb(0,0,0)"> 中備份 </span><span style="color: rgb(0,0,255)">Transaction</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(255,0,255)">Log</span><span style="color: rgb(0,0,0)"> 語法改為 </span><span style="color: rgb(0,0,255)">Backup</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(255,0,255)">LOG</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">BACKUP</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(255,0,255)">LOG</span><span style="color: rgb(0,0,0)"> DBName </span><span style="color: rgb(0,0,255)">WITH</span><span style="color: rgb(0,0,0)"> NO_LOG </span><span style="color: rgb(0,0,255)">DBCC</span><span style="color: rgb(0,0,0)"> SHRINKFILE(</span><span style="color: rgb(128,0,0); font-weight: bold">2</span><span style="color: rgb(0,0,0)">,</span><span style="color: rgb(128,0,0); font-weight: bold">200</span><span style="color: rgb(0,0,0)">) SQL </span><span style="color: rgb(128,0,0); font-weight: bold">2008</span><span style="color: rgb(0,0,0)">: 必須先將復原模式改為 "簡單" 才能清除,完成之後再將模式改回 "完整" </span><span style="color: rgb(0,0,255)">USE</span><span style="color: rgb(0,0,0)"> DBName </span><span style="color: rgb(0,0,255)">Alter</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">Database</span><span style="color: rgb(0,0,0)"> DBName </span><span style="color: rgb(0,0,255)">Set</span><span style="color: rgb(0,0,0)"> Recovery Simple </span><span style="color: rgb(0,0,255)">DBCC</span><span style="color: rgb(0,0,0)"> SHRINKFILE(</span><span style="color: rgb(128,0,0); font-weight: bold">2</span><span style="color: rgb(0,0,0)">,</span><span style="color: rgb(128,0,0); font-weight: bold">100</span><span style="color: rgb(0,0,0)">) </span><span style="color: rgb(0,0,255)">Alter</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">Database</span><span style="color: rgb(0,0,0)"> DBName </span><span style="color: rgb(0,0,255)">Set</span><span style="color: rgb(0,0,0)"> Recovery </span><span style="color: rgb(0,0,255)">Full </span><span style="color: rgb(0,0,0)"> SQL </span><span style="color: rgb(128,0,0); font-weight: bold">2008</span><span style="color: rgb(0,0,0)"> R2: </span><span style="color: rgb(0,0,255)">USE</span><span style="color: rgb(0,0,0)"> DBName; </span><span style="color: rgb(0,0,255)">GO</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)"> Truncate the log by changing the database recovery model to SIMPLE.</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,255)">ALTER</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">DATABASE</span><span style="color: rgb(0,0,0)"> DBName </span><span style="color: rgb(0,0,255)">SET</span><span style="color: rgb(0,0,0)"> RECOVERY SIMPLE; </span><span style="color: rgb(0,0,255)">GO</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)"> Shrink the truncated log file to 10 MB.</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,255)">DBCC</span><span style="color: rgb(0,0,0)"> SHRINKFILE (</span><span style="color: rgb(128,0,0); font-weight: bold">2</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0); font-weight: bold">10</span><span style="color: rgb(0,0,0)">); </span><span style="color: rgb(0,0,255)">GO</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,128,128)">--</span><span style="color: rgb(0,128,128)"> Reset the database recovery model.</span><span style="color: rgb(0,128,128)"> </span><span style="color: rgb(0,0,255)">ALTER</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">DATABASE</span><span style="color: rgb(0,0,0)"> DBName </span><span style="color: rgb(0,0,255)">SET</span><span style="color: rgb(0,0,0)"> RECOVERY </span><span style="color: rgb(0,0,255)">FULL</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">GO</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,128,128)">*</span><span style="color: rgb(0,0,0)">上述 </span><span style="color: rgb(0,0,255)">DBCC</span><span style="color: rgb(0,0,0)"> SHRINKFILE (</span><span style="color: rgb(128,0,0); font-weight: bold">2</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0); font-weight: bold">10</span><span style="color: rgb(0,0,0)">),2指的是LOG </span><span style="color: rgb(0,0,255)">File</span><span style="color: rgb(0,0,0)">, 10指的是壓到10MB哦!</span></div> </div> </div>
试试其它关键字
清理日志
同语言下
.
SQL查询 多列合并成一行用逗号隔开
.
查看存储过程修改时间,最近执行时间
.
设置手动批量删除数据库相关进程
.
获取某个表中特定字段的所有字符串形式
.
SQL 如何去除重复的字符串
.
怎么去掉一个字段中的重复数据
.
String 去除空格 回车 换行 水平制表符
.
SQL查询和替换含有回车,空格,TAB
.
SQL SERVER 查询每日新增用户数量、次留数量
.
判断两个字符串是否存在相同的内容
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3