惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Schneier on Security
A
Arctic Wolf
Scott Helme
Scott Helme
S
Securelist
Schneier on Security
Schneier on Security
W
WeLiveSecurity
Attack and Defense Labs
Attack and Defense Labs
Security Latest
Security Latest
Project Zero
Project Zero
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed
C
Check Point Blog
F
Full Disclosure
Stack Overflow Blog
Stack Overflow Blog
H
Hacker News: Front Page
T
The Blog of Author Tim Ferriss
TaoSecurity Blog
TaoSecurity Blog
Vercel News
Vercel News
A
About on SuperTechFans
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The GitHub Blog
The GitHub Blog
S
Security Affairs
Y
Y Combinator Blog
T
The Exploit Database - CXSecurity.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Forbes - Security
Forbes - Security
IT之家
IT之家
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
Jina AI
Jina AI
云风的 BLOG
云风的 BLOG
T
Tailwind CSS Blog
K
Kaspersky official blog
Hacker News: Ask HN
Hacker News: Ask HN
C
Cisco Blogs
MyScale Blog
MyScale Blog
博客园 - 【当耐特】
T
Threat Research - Cisco Blogs
D
Docker
G
GRAHAM CLULEY

博客园 - 天马行空(笨笨)

libcurl的使用(转) 使用Visual Studio 2010 Team System中的架构师工具(设计与建模) Silverlight 框架介绍 Silverlight 介绍(转) 使用MAP文件快速定位程序崩溃代码行(转) Pocket PC 模拟器上网设置 解决继承窗体或用户控件时“visual继承当前被禁用,因为基类引用设备特定的组件或包含 p/invoke”问题(转) 操作MSN(IM)相关的资源 用户中心 - 博客园 .net的辅助工具列表 Eclipse+JDK+API中文帮助文档的java开发环境搭建 淺談如何使用Delphi 2009的泛型容器類別 Delphi2009带来了什么 NET开源项目链接(转载) Google Chrome 源码下载 版本控制工具SVN和CVS 用DOS命令安装删除服务 我要向党和人民道歉:我错了(韩国行有感)--转贴 论韩寒"大师"与鲁迅先生
压缩SQLServer数据库日志的一个存储过程
天马行空(笨笨) · 2008-11-20 · via 博客园 - 天马行空(笨笨)

use master  --注意,此存储过程要建在master数据库中
go

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_compdb]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_compdb]
GO

create proc p_compdb
@dbname sysname,   --要压缩的数据库名
@bkdatabase bit=1,   --因为分离日志的步骤中,可能会损坏数据库,所以你可以选择是否自动数据库
@bkfname nvarchar(260)='' --备份的文件名,如果不指定,自动备份到默认备份目录,备份文件名为:数据库名+日期时间
as
--1.清空日志
exec('DUMP TRANSACTION ['+@dbname+'] WITH  NO_LOG')

--2.截断事务日志:
exec('BACKUP LOG ['+@dbname+'] WITH NO_LOG')

--3.收缩数据库文件(如果不压缩,数据库的文件不会减小
exec('DBCC SHRINKDATABASE(['+@dbname+'])')

--4.设置自动收缩
exec('EXEC sp_dboption '''+@dbname+''',''autoshrink'',''TRUE''')

--后面的步骤有一定危险,你可以可以选择是否应该这些步骤
--5.分离数据库
if @bkdatabase=1
begin
 if isnull(@bkfname,'')=''
  set @bkfname=@dbname+'_'+convert(varchar,getdate(),112)
   +replace(convert(varchar,getdate(),108),':','')
 select 提示信息='备份数据库到SQL 默认备份目录,备份文件名:'+@bkfname
 exec('backup database ['+@dbname+'] to disk='''+@bkfname+'''')
end

--进行分离处理
create table #t(fname nvarchar(260),type int)
exec('insert into #t select filename,type=status&0x40 from ['+@dbname+']..sysfiles')
exec('sp_detach_db '''+@dbname+'''')

--删除日志文件
declare @fname nvarchar(260),@s varchar(8000)
declare tb cursor local for select fname from #t where type=64
open tb
fetch next from tb into @fname
while @@fetch_status=0
begin
 set @s='del "'+rtrim(@fname)+'"'
 exec master..xp_cmdshell @s,no_output
 fetch next from tb into @fname
end
close tb
deallocate tb

--附加数据库
set @s=''
declare tb cursor local for select fname from #t where type=0
open tb
fetch next from tb into @fname
while @@fetch_status=0
begin
 set @s=@s+','''+rtrim(@fname)+''''
 fetch next from tb into @fname
end
close tb
deallocate tb
exec('sp_attach_single_file_db '''+@dbname+''''+@s)
go

/*--调用示例
 exec p_compdb 'test'
--*/