国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > SQL Server > 正文

Sql Server實用操作小技巧集合

2024-08-31 00:48:14
字體:
來源:轉載
供稿:網(wǎng)友

包括安裝時提示有掛起的操作、收縮數(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)站源碼資源下載站,

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 湖北省| 栖霞市| 玛多县| 崇明县| 民乐县| 北川| 衡南县| 平果县| 商丘市| 宜都市| 当涂县| 奇台县| 司法| 金乡县| 莲花县| 郴州市| 梧州市| 大渡口区| 靖边县| 甘洛县| 龙海市| 西华县| 绩溪县| 清苑县| 巍山| 阆中市| 同仁县| 额尔古纳市| 大关县| 泽州县| 当涂县| 乐安县| 睢宁县| 社会| 阿拉善右旗| 广昌县| 仁寿县| 姜堰市| 九龙城区| 石首市| 保定市|