How to Fix the problem - No Data for the 5 views in AdventureWorksDW2008R2


Problem:

Today, I found there are no data for the 5 views in the AdventureWorksDW2008R2 database.

Solution:


  1. Detach the current AdventureWorksDW2008R2 (disconnect the current connection first if necessary)
  2. Run the codes below  in the Instawdwdb file (from the downloaded AdventureWorks 2008R2 Data Warehouse) in SQLCMD mode.
  3. Change the file path if necessary based on the error messages.


Note: 

:setvar SqlSamplesDatabasePath   "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\"
(the mdf and ldf files may need to be deleted from this location for re-run)

:setvar SqlSamplesSourceDataPath "C:\Program Files\Microsoft SQL Server\100\Tools\Samples\AdventureWorks 2008R2 Data Warehouse\" (the last part is the path on my machine - this is where all of the data files are)

/*======================================================================
  File:     instawdwdb.sql

  Summary:   Creates the AdventureWorks 2008R2 data warehouse sample database.

  Date:     June 14, 2008
  Updated: March 28, 2012

  -- TODO: Verify
  SQL Server Version: 10.50.1600
------------------------------------------------------------------------------
  This file is part of the Microsoft SQL Server Code Samples.

  Copyright (C) Microsoft Corporation.  All rights reserved.

  This source code is intended only as a supplement to Microsoft
  Development Tools and/or on-line documentation.  See these other
  materials for detailed information regarding Microsoft code samples.

  THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  PARTICULAR PURPOSE.
=======================================================================*/

-->> WARNING: THIS SCRIPT MUST BE RUN IN SQLCMD MODE INSIDE SQL SERVER MANAGEMENT STUDIO. <<--
:on error exit

/*
 * In order to run this script manually, either set the environment variables,
 * or uncomment the setvar statements and provide the necessary values if
 * the defaults are not correct for your installation.
 */

:setvar SqlSamplesDatabasePath   "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\"
:setvar SqlSamplesSourceDataPath "C:\Program Files\Microsoft SQL Server\100\Tools\Samples\AdventureWorks 2008R2 Data Warehouse\"
===================

The rest are omitted