包括安裝時提示有掛起的操作、收縮數(shù)據(jù)庫、壓縮數(shù)據(jù)庫、轉移數(shù)據(jù)庫給新用戶以已存在用戶權限、檢查備份集、修復數(shù)據(jù)庫等 
 (一)掛起操作
在安裝sql或sp補丁的時候系統(tǒng)提示之前有掛起的安裝操作,要求重啟,這里往往重啟無用,解決辦法:
到hkey_local_machine ystem/currentcontrolset/control ession manager
刪除pendingfilerenameoperations
(二)收縮數(shù)據(jù)庫
--重建索引
dbcc reindex
dbcc indexdefrag
--收縮數(shù)據(jù)和日志
dbcc shrinkdb
dbcc shrinkfile
(三)壓縮數(shù)據(jù)庫
dbcc shrinkdatabase(dbname)
(四)轉移數(shù)據(jù)庫給新用戶以已存在用戶權限
exec sp_change_users_login 'update_one','newname','oldname'
go
(五)檢查備份集
restore verifyonly from disk='e:/dvbbs.bak'
(六)修復數(shù)據(jù)庫
alter database [dvbbs] set single_user
go
dbcc checkdb('dvbbs',repair_allow_data_loss) with tablock
go
alter database [dvbbs] set multi_user
go
--checkdb 有3個參數(shù):
--repair_allow_data_loss 
--  執(zhí)行由 repair_rebuild 完成的所有修復,包括對行和頁進行分配和取消分配以改正分配錯誤、結構行或頁的錯誤,以及刪除已損壞的文本對象。這些修復可能會導致一些數(shù)據(jù)丟失。修復操作可以在用戶事務下完成以允許用戶回滾所做的更改。如果回滾修復,則數(shù)據(jù)庫仍會含有錯誤,應該從備份進行恢復。如果由于所提供修復等級的緣故遺漏某個錯誤的修復,則將遺漏任何取決于該修復的修復。修復完成后,備份數(shù)據(jù)庫。 
--repair_fast 進行小的、不耗時的修復操作,如修復非聚集索引中的附加鍵。這些修復可以很快完成,并且不會有丟失數(shù)據(jù)的危險。 
--repair_rebuild 執(zhí)行由 repair_fast 完成的所有修復,包括需要較長時間的修復(如重建索引)。執(zhí)行這些修復時不會有丟失數(shù)據(jù)的危險。 
--dbcc checkdb('dvbbs') with no_infomsgs,physical_only
sql server日志清除的兩種方法
在使用過程中大家經(jīng)常碰到數(shù)據(jù)庫日志非常大的情況,在這里介紹了兩種處理方法…… 
方法一
一般情況下,sql數(shù)據(jù)庫的收縮并不能很大程度上減小數(shù)據(jù)庫大小,其主要作用是收縮日志大小,應當定期進行此操作以免數(shù)據(jù)庫日志過大
1、設置數(shù)據(jù)庫模式為簡單模式:打開sql企業(yè)管理器,在控制臺根目錄中依次點開microsoft sql server-->sql server組-->雙擊打開你的服務器-->雙擊打開數(shù)據(jù)庫目錄-->選擇你的數(shù)據(jù)庫名稱(如論壇數(shù)據(jù)庫forum)-->然后點擊右鍵選擇屬性-->選擇選項-->在故障還原的模式中選擇“簡單”,然后按確定保存
2、在當前數(shù)據(jù)庫上點右鍵,看所有任務中的收縮數(shù)據(jù)庫,一般里面的默認設置不用調整,直接點確定
3、收縮數(shù)據(jù)庫完成后,建議將您的數(shù)據(jù)庫屬性重新設置為標準模式,操作方法同第一點,因為日志在一些異常情況下往往是恢復數(shù)據(jù)庫的重要依據(jù)
方法二
set nocount on
declare @logicalfilename sysname,
        @maxminutes int,
        @newsize int
use     tablename             -- 要操作的數(shù)據(jù)庫名
select  @logicalfilename = 'tablename_log',  -- 日志文件名
@maxminutes = 10,               -- limit on time allowed to wrap log.
        @newsize = 1                  -- 你想設定的日志文件的大小(m)
-- setup / initialize
declare @originalsize int
select @originalsize = size 
  from sysfiles
  where name = @logicalfilename
select 'original size of ' + db_name() + ' log is ' + 
        convert(varchar(30),@originalsize) + ' 8k pages or ' + 
        convert(varchar(30),(@originalsize*8/1024)) + 'mb'
  from sysfiles
  where name = @logicalfilename
create table dummytrans
  (dummycolumn char (8000) not null)
declare @counter   int,
        @starttime datetime,
        @trunclog  varchar(255)
select  @starttime = getdate(),
        @trunclog = 'backup log ' + db_name() + ' with truncate_only'
dbcc shrinkfile (@logicalfilename, @newsize)
exec (@trunclog)
-- wrap the log if necessary.
while     @maxminutes > datediff (mi, @starttime, getdate()) -- time has not expired
      and @originalsize = (select size from sysfiles where name = @logicalfilename)  
      and (@originalsize * 8 /1024) > @newsize  
  begin -- outer loop.
    select @counter = 0
    while  ((@counter < @originalsize / 16) and (@counter < 50000))
      begin -- update
        insert dummytrans values ('fill log')  
        delete dummytrans
        select @counter = @counter + 1
      end   
    exec (@trunclog)  
  end   
select 'final size of ' + db_name() + ' log is ' +
        convert(varchar(30),size) + ' 8k pages or ' + 
        convert(varchar(30),(size*8/1024)) + 'mb'
  from sysfiles 
  where name = @logicalfilename
drop table dummytrans
set nocount off 
最大的網(wǎng)站源碼資源下載站,
新聞熱點
疑難解答
圖片精選