home
training courses
why choose us?
solutions
support
company
LearnItFirst User Forum
Welcome Guest
Search
|
New Posts
|
Members
|
Log In
|
Register
SQL Server Forum - LearnItFirst.com
»
SQL Server Scripts, Code Samples and SSMS Custom Reports
»
SQL Server 2005/2008
»
Upgrade SQL Server 2000 Database to SQL Server 2005 script
Upgrade SQL Server 2000 Database to SQL Server 2005 script
Options
Previous Topic
·
Next Topic
Scott Whigham
Posted:
Thursday, August 31, 2006 6:34:30 AM
Rank: Super Mod
Joined: 3/20/2006
Posts: 476
Points: 1,053
Where do you live?: Dallas, TX
Code:
USE master
GO
CREATE PROC dbo.DBA_UpgradeSql2000Database (@DbName SYSNAME)
AS
/*
Author: Scott Whigham from
http://www.LearnSqlServer.com/
Description: This proc updates the database settings for any database upgraded from SQL Server 2000
to be the recommended/generally-used settings in SQL Server 2005. When you restore a database
from SQL Server 2000 onto SQL Server 2005, the database settings may not be ideal. This proc ensures
consistency among databases.
Misc Notes: One major thing you need to do is to change the compatibility mode/level of the "new" database.
This proc cannot do that because you are not allowed to execute sp_dbcmptlevel outside of any other
context; i.e. you can't execute sp_dbcmptlevel from inside a stored procedure for example.
Versions: SQL Server 2005
Creation Date: August 31, 2006
For more scripts like this one, visit
http://forums.learnsqlserver.com/codesamples.aspx
To make it easier to call this proc, this allows 'Northwind', "Northwind", [Northwind] or Northwind;
they all get treated the same.
@DbName_Formatted = [Northwind] for the ALTER DATABASE statement
@DbName is left the same because, for whatever reason, sp_helpdb cannot use @DbName_Formatted
although you can pass in EXEC sp_helpdb [Northwind] and it works fine
*/
DECLARE @DbName_Formatted SYSNAME
SET @DbName_Formatted = REPLACE(@DbName, '''', '') -- replace single quotes
SET @DbName_Formatted = REPLACE(@DbName_Formatted, '"', '') -- replace double quotes
SET @DbName_Formatted = REPLACE(@DbName_Formatted, '[', '') -- replace [
SET @DbName_Formatted = REPLACE(@DbName_Formatted, ']', '') -- replace ]
SET @DbName_Formatted = '[' + @DbName_Formatted + ']'
-- Can't call sp_dbcmptlevel from inside another proc; must do this separately
-- EXEC sys.sp_dbcmptlevel @dbname=@DbName, @new_cmptlevel=90
DECLARE @DynamicSql NVARCHAR(1024)
SET @DynamicSql = '
ALTER DATABASE ' + @DbName_Formatted + '
SET ANSI_NULL_DEFAULT ON
, ANSI_NULLS ON
, ANSI_PADDING ON
, ANSI_WARNINGS ON
, ARITHABORT ON
, AUTO_CREATE_STATISTICS ON
, AUTO_UPDATE_STATISTICS ON
, NUMERIC_ROUNDABORT ON
, PAGE_VERIFY CHECKSUM
WITH NO_WAIT
'
EXEC sp_executesql @DynamicSql
PRINT @DynamicSql
EXEC sp_helpdb @DbName
GO
EXEC DBA_UpgradeSql2000Database joplin
EXEC sys.sp_dbcmptlevel joplin, 90
Back to top
Users browsing this topic
Guest
Forum Jump
SQL Server Database Administration
- General SQL Database Question & Answer
- Backup, Recovery and Disaster Recovery
- SQL Server Security
- Integration Services (SSIS) and DTS
Transact-SQL Programming
- DML (SELECT, INSERT, UPDATE, DELETE) Questions
- Stored Procedures, Triggers, & Functions
SQL Server Scripts, Code Samples and SSMS Custom Reports
- All SQL Server Versions
- SQL Server 2005/2008
- SQL Server Management Studio Custom Reports
Customer Service
- Video Requests
You
cannot
post new topics in this forum.
You
cannot
reply to topics in this forum.
You
cannot
delete your posts in this forum.
You
cannot
edit your posts in this forum.
You
cannot
create polls in this forum.
You
cannot
vote in polls in this forum.
SQL Server 2005 DBA Training Videos
SQL Server 2008 DBA Training Videos
Email this topic
RSS Feed
Watch this topic
Print this topic
Normal
Threaded