Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/databases/wide-world-importers/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# WideWorldImporters Sample Database for SQL Server and Azure SQL Database

WideWorldImporters is a sample for SQL Server and Azure SQL Database. It showcases best practices in database design, as well as how to best leverage SQL Server features in a database.
WideWorldImporters is a sample for SQL Server and Azure SQL Database. It showcases database design, as well as how to best leverage SQL Server features in a database.

WideWorldImporters is a wholesale company. Transactions and real-time analytics are performed in the database WideWorldImporters. The database WideWorldImportersDW is an OLAP database, focused on analytics.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Documentation for the WideWorldImporters Sample Database

This folder contains documentation for the sample.

Start with [root.md](root.md)

Note that these contents will most likely be migrated to MSDN.
65 changes: 65 additions & 0 deletions samples/databases/wide-world-importers/documentation/root.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Wide World Importers Sample for SQL Server and Azure SQL Database

Wide World Importers is a comprehensive database sample that both illustrates database design, and illustrates how SQL Server features can be leveraged in an application.

Note that the sample is meant to be representative of a typical database. It does not include every feature of SQL Server. The design of the database follows one common set of standards, but there are many ways one might build a database.

The source code for the sample can be found on the SQL Server Samples GitHub repository:
[wide-world-importers](https://github.com/Microsoft/sql-server-samples/tree/master/samples/databases/wide-world-importers).

The latest released version of the sample:
[wide-world-importers-v0.1](https://github.com/Microsoft/sql-server-samples/releases/tag/wide-world-importers-v0.1)

The documentation for the sample is organized as follows:

## Overview

__[Wide World Importers Overview](wwi-overview.md)__

Overview of the sample company Wide World Importers, and the workflows addressed by the sample.

## Main OLTP Database WideWorldImporters

__[WideWorldImporters Installation and Configuration](wwi-oltp-htap-installation.md)__

Instructions for the installation and configuration of the core database WideWorldImporters that is used for transaction processing (OLTP - OnLine Transaction Processing) and operational analytics (HTAP - Hybrid Transactional/Analytical Processing).

__[WideWorldImporters Database Catalog](wwi-oltp-htap-catalog.md)__

Description of the schemas and tables used in the WideWorldImporters database.

__[WideWorldImporters Use of SQL Server Features and Capabilities](wwi-oltp-htap-sql-features.md)__

Describes how WideWorldImporters leverages core SQL Server features.

__[WideWorldImporters Sample Queries](wwi-oltp-htap-sample-queries.md)__

Sample queries for the WideWorldImporters database.

## Data Warehousing and Analytics Database WideWorldImportersDW

__[WideWorldImportersDW Installation and Configuration](wwi-olap-installation.md)__

Instructions for the installation and configuration of the OLAP database WideWorldImportersDW.

__[WideWorldImportersDW OLAP Database Catalog](wwi-olap-catalog.md)__

Description of the schemas and tables used in the WideWorldImportersDW database, which is the sample database for data warehousing and analytics processing (OLAP).

__[WideWorldImporters ETL Workflow](wwi-etl.md)__

Workflow for the ETL (Extract, Transform, Load) process that migrates data from the transactional database WideWorldImporters to the data warehouse WideWorldImportersDW.

__[WideWorldImportersDW Use of SQL Server Features and Capabilities](wwi-olap-sql-features.md)__

Describes how the WideWorldImportersDW leverages SQL Server features for analytics processing.

__[WideWorldImportersDW OLAP Sample Queries](wwi-olap-sample-queries.md)__

Sample analytics queries leveraging the WideWorldImportersDW database.

## Data generation

__[WideWorldImporters Data Generation](wwi-data-generation.md)__

Describes how additional data can be generated in the sample database, for example inserting sales and purchase data up to the current date.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# WideWorldImporters Data Generation

The released versions of the WideWorldImporters and WideWorldImportersDW databases contains data starting January 1st 2013, up to the day these databases were generated.

If the sample databases are used at a later date, for demonstration or illustration purposes, it may be beneficial to include more recent sample data in the database.

## Data Generation in WideWorldImporters

To generate sample data up to the current date, follow these steps:

1. If you have not yet done so, install a clean version of the WideWorldImporters database. For installation instructions, [WideWorldImporters Installation and Configuration](wwi-oltp-htap-installation.md).
2. Execute the following statement in the database:

EXEC WideWorldImporters.DataLoadSimulation.PopulateDataToCurrentDate
@AverageNumberOfCustomerOrdersPerDay = 60,
@SaturdayPercentageOfNormalWorkDay = 50,
@SundayPercentageOfNormalWorkDay = 0,
@IsSilentMode = 1,
@AreDatesPrinted = 1;

This statement adds sample sales and purchase data in the database, up to the current date. It outputs the progress of the data generation day-by-day. It will take rougly 10 minutes for every year that needs data. Note that there are some differences in the data generated between runs, since there is a random factor in the data generation.

To increase or decrease the amount of data generated, in terms of orders per day, change the value for the parameter `@AverageNumberOfCustomerOrdersPerDay`. The parameters `@SaturdayPercentageOfNormalWorkDay` and `@SundayPercentageOfNormalWorkDay` are used to determine the order volume for weekend days.

## Importing Data in WideWorldImportersDW

To import sample data up to the current date in the OLAP database WideWorldImportersDW, follow these steps:

1. Execute the data generation logic in the WideWorldImporters OLTP database, using the steps above.
2. If you have not yet done so, install a clean version of the WideWorldImportersDW database. For installation instructions, [WideWorldImporters Installation and Configuration](wwi-olap-installation.md).
3. Reseed the OLAP database by executing the following statement in the database:

EXECUTE [Application].Configuration_ReseedETL

4. Run the SSIS package **Daily ETL.ispac** to import the data into the OLAP database. For instructions on how to run the ETL job, see [WideWorldImporters ETL Workflow](wwi-etl.md).
58 changes: 58 additions & 0 deletions samples/databases/wide-world-importers/documentation/wwi-etl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# WideWorldImporters ETL Workflow

The ETL package WWI_Integration is used to migrate data from the WideWorldImporters database to the WideWorldImportersDW database as the data changes. The package is run periodically (most commonly daily).

## Overview

The design of the package uses SQL Server Integration Services (SSIS) to orchestrate bulk T-SQL operations (rather than as separate transformations within SSIS) to ensure high performance.

Dimensions are loaded first, followed by Fact tables. The package can be re-run at any time after a failure.

The workflow is as follows:

![Alt text](/media/wide-world-importers-etl-workflow.png "WideWorldImporters ETL Workflow")

It starts with an expression task that works out the appropriate cutoff time. This time is the current time less a few seconds. (This is more robust than requesting data right to the current time). It then truncates any milliseconds from the time.

The main processing starts by populating the Date dimension table. It ensures that all dates for the current year have been populated in the table.

After this, a series of data flow tasks loads each dimension, then each fact.

## Prerequisites

- SQL Server 2016 (or higher) with the databases WideWorldImporters and WideWorldImportersDW. These can be on the same or different instances of SQL Server.
- SQL Server Management Studio (SSMS)
- SQL Server 2016 Integration Services (SSIS).
- Make sure you have created an SSIS Catalog. If not, right click **Integration Services** in SSMS Object Explorer, and choose **Add Catalog**. Follow the defaults. It will ask you to enable sqlclr and provide a password.


## Download

The latest release of the sample:

[wide-world-importers-v0.1](https://github.com/Microsoft/sql-server-samples/releases/tag/wide-world-importers-v0.1)

Download the SSIS package file **Daily ETL.ispac**.

Source code to recreate the sample database is available from the following location.

[wide-world-importers](https://github.com/Microsoft/sql-server-samples/tree/master/samples/databases/wide-world-importers/wwi-integration-etl)

## Install

1. Deploy the SSIS package.
- Open the "Daily ETL.ispac" package from Windows Explorer. This will launch the Integration Services Deployment Wizard.
- Under "Select Source" follow the default Project Deployment, with the path pointing to the "Daily ETL.ispac" package.
- Under "Select Destination" enter the name of the server that hosts the SSIS catalog.
- Select a path under the SSIS catalog, for example under a new folder "WideWorldImporters".
- Finalize the wizard by clicking Deploy.

2. Create a SQL Server Agent job for the ETL process.
- In SSMS, right-click "SQL Server Agent" and select New->Job.
- Pick a name, for example "WideWorldImporters ETL".
- Add a Job Step of type "SQL Server Integration Services Package".
- Select the server with the SSIS catalog, and select the "Daily ETL" package.
- Under Configuration->Connection Managers ensure the connections to the source and target are configured correctly. The default is to connect to the local instance.
- Click OK to create the Job.

3. Execute or schedule the Job.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# WideWorldImportersDW OLAP Database Catalog

The WideWorldImportersDW database is used for data warehousing and analytical processing. The transactional data about sales and purchases is generated in the WideWorldImporters database, and loaded into the WideWorldImportersDW database using a [daily ETL process](wwi-etl.md).

The data in WideWorldImportersDW thus mirrors the data in WideWorldImporters, but the tables are organized differently. While WideWorldImporters has a traditional normalized schema, WideWorldImportersDW uses the [star schema](https://wikipedia.org/wiki/Star_schema) approach for its table design. Besides the fact and dimension tables, the database includes a number of staging tables that are used in the ETL process.

## Schemas

The different types of tables are organized in three schemas.

|Schema|Description|
|-----------------------------|---------------------|
|Dimension|Dimension tables.|
|Fact|Fact tables.|
|Integration|Staging tables and other objects needed for ETL.|

## Tables

The dimension and fact tables are listed below. The tables in the Integration schema are used only for the ETL process, and are not listed.

### Dimension tables

WideWorldImportersDW has the following dimension tables. The description includes the relationship with the source tables in the WideWorldImporters database.

|Table|Source tables|
|-----------------------------|---------------------|
|City|`Application.Cities`, `Application.StateProvinces`, `Application.Countries`.|
|Customer|`Sales.Customers`, `Sales.BuyingGroups`, `Sales.CustomerCategories`.|
|Date|New table with information about dates, including financial year (based on November 1st start for financial year).|
|Employee|`Application.People`.|
|StockItem|`Warehouse.StockItems`, `Warehouse.Colors`, `Warehouse.PackageType`.|
|Supplier|`Purchasing.Suppliers`, `Purchasing.SupplierCategories`.|
|PaymentMethod|`Application.PaymentMethods`.|
|TransactionType|`Application.TransactionTypes`.|

### Fact tables

WideWorldImportersDW has the following dimension tables. The description includes the relationship with the source tables in the WideWorldImporters database, as well as the classes of analytics/reporting queries each fact table is typically used with.

|Table|Source tables|Sample Analytics|
|-----------------------------|---------------------|
|Order|`Sales.Orders` and `Sales.OrderLines`|Sales people, picker/packer productivity, and on time to pick orders. In addition, low stock situations leading to back orders.|
|Sale|`Sales.Invoices` and `Sales.InvoiceLines`|Sales dates, delivery dates, profitability over time, profitability by sales person.|
|Purchase|`Purchasing.PurchaseOrderLines`|Expected vs actual lead times|
|Transaction|`Sales.CustomerTransactions` and `Purchasing.SupplierTransactions`|Measuring issue dates vs finalization dates, and amounts.|
|Movement|`Warehouse.StockTransactions`|Movements over time.|
|Stock Holding|`Warehouse.StockItemHoldings`|On-hand stock levels and value|
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# WideWorldImportersDW Installation and Configuration


- [SQL Server 2016](https://www.microsoft.com/en-us/evalcenter/evaluate-sql-server-2016) (or higher) or [Azure SQL Database](https://azure.microsoft.com/services/sql-database/). To use the Full version of the sample, use SQL Server Evaluation/Developer/Enterprise Edition.
- [SQL Server Management Studio](https://msdn.microsoft.com/library/mt238290.aspx). For the best results use the April 2016 preview or later.

## Download

The latest release of the sample:

[wide-world-importers-v0.1](https://github.com/Microsoft/sql-server-samples/releases/tag/wide-world-importers-v0.1)

Download the sample WideWorldImportersDW database backup/bacpac that corresponds to your edition of SQL Server or Azure SQL Database.

Source code to recreate the sample database is available from the following location. Note that data population is based on ETL from the OLTP database (WideWorldImporters):

[wide-world-importers](https://github.com/Microsoft/sql-server-samples/tree/master/samples/databases/wide-world-importers/wwi-dw-database-scripts)

## Install


### SQL Server

To restore a backup to a SQL Server instance, you can use Management Studio.
1. Open SQL Server Management Studio and connect to the target SQL Server instance.
2. Right-click on the **Databases** node, and select **Restore Database**.
3. Select **Device** and click on the button **...**
4. In the dialog **Select backup devices**, click **Add**, navigate to the database backup in the filesystem of the server, and select the backup. Click **OK**.
5. If needed, change the target location for the data and log files, in the **Files** pane. Note that it is best practice to place data and log files on different drives.
6. Click **OK**. This will initiate the database restore. After it completes, you will have the database WideWorldImporters installed on your SQL Server instance.

### Azure SQL Database

To import a bacpac into a new SQL Database, you can use Management Studio.
1. (optional) If you do not yet have a SQL Server in Azure, navigate to the [Azure portal](https://portal.azure.com/) and create a new SQL Database. In the process of create a database, you will create a server. Make note of the server.
- See [this tutorial](https://azure.microsoft.com/documentation/articles/sql-database-get-started/) to create a database in minutes
2. Open SQL Server Management Studio and connect to your server in Azure.
3. Right-click on the **Databases** node, and select **Import Data-Tier Application**.
4. In the **Import Settings** select **Import from local disk** and select the bacpac of the sample database from your file system.
5. Under **Database Settings** change the database name to *WideWorldImportersDW* and select the target edition and service objective to use.
6. Click **Next** and **Finish** to kick off deployment. It will take a few minutes to complete. When specifying a service objective lower than S2 it may take longer.

## Configuration

The sample database can make use of PolyBase to query files in Hadoop or Azure blob storage. However, that feature is not installed by default with SQL Server - you need to select it during SQL Server setup. Therefore, a post-installation step is required.

1. In SQL Server Management Studio, connect to the WideWorldImportersDW database and open a new query window.
2. Run the following T-SQL command to enable the use of PolyBase in the database:

EXECUTE [Application].[Configuration_ApplyPolyBase]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# WideWorldImportersDW OLAP Sample Queries

Refer to the sample-scripts.zip file that is included with the release of the sample, or refer to the source code:

[wide-world-importers/sample-scripts](https://github.com/Microsoft/sql-server-samples/tree/master/samples/databases/wide-world-importers/sample-scripts)
Loading