Step-by-Step Guide: Migrating from SQL Server 2005 to SQL Server 2008 with Best Practices


2 views

Migrating from SQL Server 2005 to 2008 requires careful planning due to several architectural changes. While the backup-restore method works in many cases, there are important compatibility considerations:

-- Sample backup command for SQL 2005
BACKUP DATABASE [YourDB] TO DISK = N'C:\Backup\YourDB.bak' 
WITH COMPRESSION, STATS = 10
GO

The SQL Server 2008 introduces new features that may affect backward compatibility:

  • New data types (DATE, TIME, DATETIME2)
  • Change in FILESTREAM implementation
  • Modified T-SQL syntax in some cases

Here's a reliable migration approach:

-- 1. Prepare target server
-- Install SQL Server 2008 with compatibility mode options
-- (Use same collation as source server)

-- 2. Script out logins (example for single login)
SELECT 'CREATE LOGIN [' + name + '] WITH PASSWORD = 0x' + 
CONVERT(VARCHAR(MAX), CAST(password AS VARBINARY(256)), 2) + ' HASHED'
FROM sys.sql_logins
WHERE name = 'YourLogin'

SQL Server Reporting Services (SSRS) underwent significant changes:

-- RS.exe script to migrate reports (save as Migration.rss)
Public Sub Main()
    Dim items As CatalogItem() = rs2005.ListChildren("/", True)
    For Each item As CatalogItem In items
        If item.Type = ItemTypeEnum.Report Then
            Dim definition As Byte() = rs2005.GetReportDefinition(item.Path)
            rs2008.CreateCatalogItem(item.Type, item.Name, item.Path, False, definition, Nothing)
        End If
    Next
End Sub
  • Update database compatibility level: ALTER DATABASE YourDB SET COMPATIBILITY_LEVEL = 100
  • Test all stored procedures and functions
  • Validate linked server connections
  • Verify job schedules in SQL Agent

If you encounter problems during restore:

-- Force restore with CONTINUE_AFTER_ERROR (use cautiously)
RESTORE DATABASE [YourDB] FROM DISK = 'C:\Backup\YourDB.bak'
WITH MOVE 'YourDB_Data' TO 'C:\Data\YourDB.mdf',
MOVE 'YourDB_Log' TO 'C:\Data\YourDB.ldf',
CONTINUE_AFTER_ERROR, STATS = 10

Remember to test the migration process in a non-production environment first and schedule appropriate downtime for production systems.


html

Migrating from SQL Server 2005 to 2008 requires careful planning due to several architectural changes. The most straightforward method is backup/restore, but you'll need to verify database compatibility first:

-- Check compatibility level before migration
SELECT name, compatibility_level 
FROM sys.databases 
WHERE name = 'YourDatabaseName';

The fundamental process involves:

  1. Creating a full backup from SQL Server 2005
  2. Restoring to SQL Server 2008 instance
-- SQL 2005 backup command
BACKUP DATABASE YourDatabase
TO DISK = 'C:\Backups\YourDatabase.bak'
WITH COMPRESSION, STATS = 10;

-- SQL 2008 restore command
RESTORE DATABASE YourDatabase
FROM DISK = 'C:\Backups\YourDatabase.bak'
WITH MOVE 'YourDatabase_Data' TO 'C:\Data\YourDatabase.mdf',
MOVE 'YourDatabase_Log' TO 'C:\Data\YourDatabase.ldf',
RECOVERY, STATS = 10;

SQL Server 2008 introduced several breaking changes:

  • Deprecated features like sp_dropalias
  • New reserved keywords (MERGE, etc.)
  • Changes to the query optimizer
-- Check for deprecated features
SELECT * 
FROM sys.dm_os_performance_counters
WHERE object_name LIKE '%Deprecated%';

SSRS underwent significant architectural changes:

  1. Backup encryption keys from 2005
  2. Install new 2008 Reporting Services
  3. Restore report server databases
  4. Apply encryption keys
-- RS 2005 key backup
rsconfig -e -m 2005Server -u Domain\Admin -p Password -f C:\backup\rsdbkey.key

-- RS 2008 key restore
rskeymgmt -a -f C:\backup\rsdbkey.key -p Password

Essential verification steps:

-- Check database status
SELECT name, state_desc, compatibility_level
FROM sys.databases;

-- Test critical stored procedures
EXEC sp_testCriticalProcedure @param1 = 'test';

Microsoft provides the SQL Server Upgrade Advisor tool which:

  • Scans for compatibility issues
  • Generates detailed reports
  • Provides remediation guidance

Always run this tool before attempting migration. Download it from Microsoft's official site.