[ SQL ] 一次修改所有的 User Databases 的 PAGE_VERIFY 為 CHECKSUM


What it is: 一次修改所有的 User Databases 的 PAGE_VERIFY 為 CHECKSUM

Why it is important: 當針對 PAGE_VERIFY 資料庫選項啟用 CHECKSUM 時,SQL Server Database Engine 會針對整頁的內容計算總和檢查碼,並在將頁面寫入磁碟時,於頁首中儲存值。 從磁碟讀取頁面時,會重新計算總和檢查碼,並與頁首所儲存的總和檢查碼值作比較。 如此有助於提供高層級的資料檔完整性。此設定為建議值。

RESOLUTION:

DECLARE @DBName varchar (50), @msg varchar (60), @sql varchar(60)

DECLARE GetDBNames CURSOR

FOR

SELECT name FROM sys.databases WHERE page_verify_option < 2 AND database_id > 4 AND is_read_only = 0

OPEN GetDBNames

FETCH NEXT FROM GetDBNames INTO @DBName

WHILE @@FETCH_STATUS = 0

BEGIN

PRINT ‘ ‘

SELECT @msg = ‘—– Change  ‘ + UPPER(RTRIM(@DBName)) + ‘ —–‘

PRINT @msg

SET @sql=’ALTER Database ‘ + @DBName + ‘ SET PAGE_VERIFY CHECKSUM’

PRINT ‘SQL Statement is ‘ + @sql

EXEC (@sql)

PRINT ‘PAGE_VERIFY changed to CHECKSUM for database = ‘ + @DBName

FETCH NEXT FROM GetDBNames INTO @DBName

END

CLOSE GetDBNames

DEALLOCATE GetDBNames

GO

 

Enjoy.

Comments (0)

Skip to main content