此文是Sql Server實用操作小技巧集合
(一)掛起操作
在安裝Sql或sp補丁的時候系統提示之前有掛起的安裝操作
到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager
刪除PendingFileRenameOperations
(二)收縮數據庫
DBCC REINDEX
DBCC INDEXDEFRAG
DBCC SHRINKDB
DBCC SHRINKFILE
(三)壓縮數據庫
dbcc shrinkdatabase(dbname)
(四)轉移數據庫給新用戶以已存在用戶權限
exec sp_change_users_login
go
(五)檢查備份集
RESTORE VERIFYONLY from disk=
(六)修復數據庫
ALTER DATABASE [dvbbs] SET SINGLE_USER
GO
DBCC CHECKDB(
GO
ALTER DATABASE [dvbbs] SET MULTI_USER
GO
SQL SERVER日志清除的兩種方法
在使用過程中大家經常碰到數據庫日志非常大的情況
方法一
一般情況下
方法二
SET NOCOUNT ON
DECLARE @LogicalFileName sysname
@MaxMinutes INT
@NewSize INT
USE tablename
SELECT @LogicalFileName =
@MaxMinutes =
@NewSize =
DECLARE @OriginalSize int
SELECT @OriginalSize = size
FROM sysfiles
WHERE name = @LogicalFileName
SELECT
CONVERT(VARCHAR(
CONVERT(VARCHAR(
FROM sysfiles
WHERE name = @LogicalFileName
CREATE TABLE DummyTrans
(DummyColumn char (
DECLARE @Counter INT
@StartTime DATETIME
@TruncLog VARCHAR(
SELECT @StartTime = GETDATE()
@TruncLog =
DBCC SHRINKFILE (@LogicalFileName
EXEC (@TruncLog)
WHILE @MaxMinutes > DATEDIFF (mi
AND @OriginalSize = (SELECT size FROM sysfiles WHERE name = @LogicalFileName)
AND (@OriginalSize *
BEGIN
SELECT @Counter =
WHILE ((@Counter < @OriginalSize /
BEGIN
INSERT DummyTrans VALUES (
DELETE DummyTrans
SELECT @Counter = @Counter +
END
EXEC (@TruncLog)
END
SELECT
CONVERT(VARCHAR(
CONVERT(VARCHAR(
FROM sysfiles
WHERE name = @LogicalFileName
DROP TABLE DummyTrans
SET NOCOUNT OFF
From:http://tw.wingwit.com/Article/program/SQLServer/201311/22232.html