自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

數(shù)據(jù)庫壓縮日志

數(shù)據(jù)庫
在進行數(shù)據(jù)庫操作時,經(jīng)常會遇到諸如此類的問題,數(shù)據(jù)庫壓縮日志文件處理不當,導(dǎo)致數(shù)據(jù)庫損壞,甚至不能恢復(fù)數(shù)據(jù),給工作人員帶來了很大的麻煩,下面就為大家介紹通用數(shù)據(jù)庫日志文件壓縮的存儲過程。

數(shù)據(jù)庫壓縮日志是數(shù)據(jù)庫操作中比較重要的環(huán)節(jié),在數(shù)據(jù)庫日志壓縮過程中隨時可能出現(xiàn)一些小差錯,下文就為大家介紹幾種解決方法。

*--壓縮數(shù)據(jù)庫的通用存儲過程

壓縮日志及數(shù)據(jù)庫文件大小
因為要對數(shù)據(jù)庫進行分離處理
所以存儲過程不能創(chuàng)建在被壓縮的數(shù)據(jù)庫中

/*--調(diào)用示例
exec p_compdb 'test'
--*/

use master --注意,此存儲過程要建在master數(shù)據(jù)庫中
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, --要壓縮的數(shù)據(jù)庫名
@bkdatabase bit=1, --因為分離日志的步驟中,可能會損壞數(shù)據(jù)庫,所以你可以選擇是否自動數(shù)據(jù)庫
@bkfname nvarchar(260)='' --備份的文件名,如果不指定,自動備份到默認備份目錄,備份文件名為:數(shù)據(jù)庫名+日期時間
as
--1.清空日志
exec('DUMP TRANSACTION ['+@dbname+'] WITH NO_LOG')

--2.截斷事務(wù)日志:
exec('BACKUP LOG ['+@dbname+'] WITH NO_LOG')

--3.收縮數(shù)據(jù)庫文件(如果不壓縮,數(shù)據(jù)庫的文件不會減小
exec('DBCC SHRINKDATABASE(['+@dbname+'])')

--4.設(shè)置自動收縮
exec('EXEC sp_dboption '''+@dbname+''',''autoshrink'',''TRUE''')

--后面的步驟有一定危險,你可以可以選擇是否應(yīng)該這些步驟
--5.分離數(shù)據(jù)庫
if @bkdatabase=1
begin
if isnull(@bkfname,'')=''
set @bkfname=@dbname+'_'+convert(varchar,getdate(),112)
+replace(convert(varchar,getdate(),108),':','')
select 提示信息='備份數(shù)據(jù)庫到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

--附加數(shù)據(jù)庫
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

這就是我要為大家介紹的關(guān)于解決數(shù)據(jù)庫壓縮日志的方法,這里只是介紹了一部分的方法,如果大家有什么更好的方法,歡迎與我們一起分享。

【編輯推薦】

  1. 數(shù)據(jù)庫開發(fā)程序員在開發(fā)過程中的注意事項
  2. PHP開源 數(shù)據(jù)庫管理
  3. 國產(chǎn)數(shù)據(jù)庫風(fēng)雨之后見彩虹
責(zé)任編輯:迎迎 來源: CSDN
相關(guān)推薦

2010-09-02 11:56:21

SQL刪除

2017-06-12 18:24:25

數(shù)據(jù)庫壓縮技術(shù)

2010-09-07 16:12:36

SQL語句數(shù)據(jù)庫壓縮

2011-04-01 12:58:46

ASPACCESS數(shù)據(jù)庫

2010-08-26 16:16:11

Infobright

2011-06-30 16:57:03

數(shù)據(jù)壓縮

2011-04-01 17:05:44

SQL Server數(shù)日志

2010-11-29 11:22:36

SYBASE數(shù)據(jù)庫日志

2019-03-01 18:50:09

SQL Server數(shù)據(jù)庫備份并壓縮

2021-10-12 10:22:33

數(shù)據(jù)庫架構(gòu)技術(shù)

2011-04-08 09:42:19

Access數(shù)據(jù)庫壓縮文件

2009-08-28 13:03:55

C#壓縮Access數(shù)

2010-11-30 13:37:02

數(shù)據(jù)庫壓縮

2011-08-09 17:24:21

SQL Server 數(shù)據(jù)庫日志

2019-08-01 07:31:51

數(shù)據(jù)庫主機日志

2024-04-02 08:21:45

數(shù)據(jù)庫日志SQL

2011-06-07 17:14:15

關(guān)系型數(shù)據(jù)庫壓縮技術(shù)

2010-01-12 10:40:58

VB.NET數(shù)據(jù)庫壓縮

2010-09-13 15:31:14

sql server數(shù)

2011-05-24 14:48:46

壓縮數(shù)據(jù)庫
點贊
收藏

51CTO技術(shù)棧公眾號