大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 数据库 -> MS_SQL -> 缩小SQL Server数据库日志

缩小SQL Server数据库日志

时间: 2021-08-13 作者:daque

  --减少日记 -- exec p_compdb ’test’  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

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.