|
導(dǎo)讀數(shù)據(jù)庫,簡而言之可視為電子化的文件柜——存儲電子文件的處所,用戶可以對文件中的數(shù)據(jù)進行新增、截取、更新、刪除等操作。所謂“數(shù)據(jù)庫”是以一定方式儲存在一起、能與多個用戶共享、具有盡可能小的冗余度、與應(yīng)... 數(shù)據(jù)庫,簡而言之可視為電子化的文件柜——存儲電子文件的處所,用戶可以對文件中的數(shù)據(jù)進行新增、截取、更新、刪除等操作。所謂“數(shù)據(jù)庫”是以一定方式儲存在一起、能與多個用戶共享、具有盡可能小的冗余度、與應(yīng)用程序彼此獨立的數(shù)據(jù)集合。 --縮小日志 -- exec p_compdb ’test’ 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 全新的路由器不僅讓你更穩(wěn)定快速地連接無線網(wǎng)絡(luò),更可以讓家中的智能設(shè)備連接在一起。 |
溫馨提示:喜歡本站的話,請收藏一下本站!