2022-05-05

Restore AdventureWorks on SQL Server 2019

 There are several SQL Server sample databases from Microsoft, and one of the easiest to start and still somewhat up-to-date is AdventureWorks. There are various versions and editions of the database, and they are described in the Microsoft document "AdventureWorks sample databases".

This is an example on how to restore AdventuresWorks on a SQL Server 2019 Database Engine instance.

Before you start restoring you have to make the backup file available to the instance. This can be done by copying the file to the default backup location.

Then you can start the restore and some minor configurations to make the database available as below.


USE [master];
RESTORE DATABASE [AdventureWorks] FROM  DISK = N'R:\BACKUP\AdventureWorks2019.bak' WITH
  MOVE N'AdventureWorks2017' TO N'R:\DATA\AdventureWorks.mdf',
  MOVE N'AdventureWorks2017_log' TO N'R:\LOGS\AdventureWorks_log.ldf',
  NORECOVERY, STATS = 5;
GO
RESTORE DATABASE [AdventureWorks] WITH RECOVERY;
GO

ALTER DATABASE [AdventureWorks] SET COMPATIBILITY_LEVEL = 150;
ALTER AUTHORIZATION ON DATABASE::[AdventureWorks] TO [sa];
GO
ALTER DATABASE [AdventureWorks] MODIFY FILE (NAME=N'AdventureWorks2017', NEWNAME=N'AdventureWorks');
ALTER DATABASE [AdventureWorks] MODIFY FILE (NAME=N'AdventureWorks2017_log', NEWNAME=N'AdventureWorks_log');
GO
EXECUTE [AdventureWorks].sys.sp_updateextendedproperty
  @name=N'MS_Description',
  @value=N'AdventureWorks Sample OLTP Database' ;
GO

-- Option
ALTER DATABASE [AdventureWorks] SET QUERY_STORE = ON;
ALTER DATABASE [AdventureWorks] SET QUERY_STORE (OPERATION_MODE = READ_WRITE);
GO

The configurations are not necessary to make the database available to you, but they are nice to make it general available and functional on SQL Server 2019. Configuring Query Store on the database is optional, but could be handy on a non-production instance.

No comments: