Tuesday, 19 September 2017

Installing AdventureWorks2014 Sample Database

Installing AdventureWorks Sample Database


Now the SQL Server and the management studio are ready for using. For training purpose, we need a database with some sample data. It will be very helpful to have a sample database while learning SQL Server. For this purpose, Microsoft has introduced the AdventureWorks Sample Database. Currently, AdventureWorks sample database is available in CodePlex as open source.

Downloading & Extracting AdventureWorks Sample Database

  1. You can download the sample databases for SQL Server 2014 from CodePlex. There you can see all the different types of sample databases available for download.
  2. From the list, download the Adventure Works 2014 Full Database Backup.zip below the Recommended Download Section. This is the sample database useful for learning SQL Server basics.
https://msftdbprodsamples.codeplex.com/releases/view/125550


  1. Once downloaded, unzip the file to extract the sample database backup file named AdventureWorks2014.bak.
  2. Place the backup file (AdventureWorks2014.bak) under the default SQL Server 2014 backup folder.
    • On 64 bit operating system, the default backup folder will be like C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\.
    • On 32 bit OS, use C:\Program Files (x86)\Microsoft SQL Server\…..
  3. Now, follow one of the below methods to restore this backup file to the SQL Server.

Installing Or Restoring The AdventureWorks Sample Database

A. Restore Sample Database Using SQL Scripts

  1. Login to the SQL Server Management Studio (SSMS).
  2. Open a new SQL Query Editor window
  3. Copy the below code and paste it into the query editor window
    1
    2
    3
    4
    5
    6
    7
    8
    9
    USE master
    RESTORE DATABASE AdventureWorks2014
    FROM disk =
    'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\AdventureWorks2014.bak'
    WITH MOVE 'AdventureWorks2014_data' TO
    'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\AdventureWorks2014.mdf',
    MOVE 'AdventureWorks2014_Log' TO
    'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\AdventureWorks2014.ldf',
    REPLACE
  4. Click the Execute icon in the toolbar. You will see the status message as in the below picture once the database is successfully restored.
  5. You can see the restored sample database in the Object Explorer under Databases folder.

B. Restore Sample Database Using SSMS GUI

  1. Login to the SQL Server Management Studio (SSMS).
  2. In the Object Explorer, right-click  the Database folder and select Restore Database...
  3. In the Restore Database screen, choose Devices and click the ellipsis button to launch the backup device selection screen. In the device selection window, press Add button to launch the file dialog. The file dialog will open the default SQL Server backup location. As we have already placed the backup file in that location, just select the backup file in the file dialog and press OK. Again press OK in the device selection window.
  4. Now the restore database window is filled with the details of the database to be restored from the backup.
  5. Press the OK button in restore database window. The sample database backup is restored as a new database AdventureWorks2014. You can see the restored sample database in the Object Explorerunder Databases folder.
In my future article on SQL Server Basics series, I’ll be using this sample database for training.

Disable CDC at table level

 How to Disable CDC( Change Data Capture) for tables Change Data Capture (cdc) property is disabled as default.  here I will Query you how t...