Member of the LearnItFirst.com Video Training Network | LearnSqlServer.com | SQL SSIS Training | SQL Programming Tutorials |
LearnSqlServer.com Forums LearnSqlServer.com
Welcome Guest Search | New Posts | Members | Log In | Register

Upgrade SQL Server 2000 Database to SQL Server 2005 script Options
Scott Whigham
Posted: Thursday, August 31, 2006 6:34:30 AM


Rank: Super Mod

Joined: 3/20/2006
Posts: 329
Points: 700
Location: 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
Users browsing this topic
Guest


Forum Jump
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.
     
Don't Forget!
LearnItFirst.com
Don't Forget!
LearnSqlServe.com
 
Home | About Us | Support | Contact Us | Privacy | Site Map | Blogs Blogs Refer a Friend and Get a Free Subscription!
© Copyright 2004-2007 LearnItFirst.com LLC. All rights reserved. All trademarks remain the property of their respective owners.
This site is not affiliated in any way with the Microsoft Corporation.