Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pollusb/7034600 to your computer and use it in GitHub Desktop.
Save pollusb/7034600 to your computer and use it in GitHub Desktop.
Just after migrating/upgrade databases to SQL Server
-- Change DB Owner, Compatibility Level and Page Verify
use master
go
declare @cmptlevel int
select @cmptlevel = compatibility_level from sys.databases where database_id = 1
select 'ALTER DATABASE ['+name+'] SET COMPATIBILITY_LEVEL = ' + cast(@cmptlevel as varchar) + ';'
from sys.databases
where database_id > 4 and compatibility_level < @cmptlevel
select 'use ['+name+'];exec sp_changedbowner ''sa'';'
from sys.databases
where database_id > 4 and owner_sid <> 1
select 'ALTER DATABASE ['+name+'] SET PAGE_VERIFY CHECKSUM;'
from sys.databases
where database_id > 4 and page_verify_option <> 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment