diff --git a/samples/databases/wide-world-importers/documentation/root.md b/samples/databases/wide-world-importers/documentation/root.md index 72f6c331..27a29da5 100644 --- a/samples/databases/wide-world-importers/documentation/root.md +++ b/samples/databases/wide-world-importers/documentation/root.md @@ -1,7 +1,51 @@ -# Documentation for the WideWorldImporters Sample Database +# Wide World Importers Sample for SQL Server and Azure SQL Database -This folder contains documentation for the sample. +Wide World Importers is a comprehensive database sample that both illustrates best practices in database design, and illustrates how SQL Server features can be leveraged in an application. -Start with [root.md](root.md) +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). -Note that these contents will most likely be migrated to MSDN. +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: + +__[Wide World Importers Overview](wwi-overview.md)__ + +Overview of the sample company Wide World Importers, and the workflows addressed by the sample. + +__[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 Transaction and Analytics 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-catalog.md)__ + +Describes how WideWorldImporters leverages core SQL Server features. + +__[WideWorldImporters Sample Queries](wwi-oltp-htap-sample-queries.md)__ + +Sample queries for the WideWorldImporters database. + +__[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. diff --git a/samples/databases/wide-world-importers/documentation/wwi-etl.md b/samples/databases/wide-world-importers/documentation/wwi-etl.md index 72f6c331..0caa5c94 100644 --- a/samples/databases/wide-world-importers/documentation/wwi-etl.md +++ b/samples/databases/wide-world-importers/documentation/wwi-etl.md @@ -1,4 +1,4 @@ -# Documentation for the WideWorldImporters Sample Database +# WideWorldImporters ETL Workflow This folder contains documentation for the sample. diff --git a/samples/databases/wide-world-importers/documentation/wwi-olap-catalog.md b/samples/databases/wide-world-importers/documentation/wwi-olap-catalog.md index 72f6c331..beba4c28 100644 --- a/samples/databases/wide-world-importers/documentation/wwi-olap-catalog.md +++ b/samples/databases/wide-world-importers/documentation/wwi-olap-catalog.md @@ -1,4 +1,4 @@ -# Documentation for the WideWorldImporters Sample Database +# WideWorldImportersDW OLAP Database Catalog This folder contains documentation for the sample. diff --git a/samples/databases/wide-world-importers/documentation/wwi-olap-installation.md b/samples/databases/wide-world-importers/documentation/wwi-olap-installation.md index 72f6c331..8db2a5f3 100644 --- a/samples/databases/wide-world-importers/documentation/wwi-olap-installation.md +++ b/samples/databases/wide-world-importers/documentation/wwi-olap-installation.md @@ -1,4 +1,4 @@ -# Documentation for the WideWorldImporters Sample Database +# WideWorldImportersDW Installation and Configuration This folder contains documentation for the sample. diff --git a/samples/databases/wide-world-importers/documentation/wwi-olap-overview.md b/samples/databases/wide-world-importers/documentation/wwi-olap-overview.md deleted file mode 100644 index 72f6c331..00000000 --- a/samples/databases/wide-world-importers/documentation/wwi-olap-overview.md +++ /dev/null @@ -1,7 +0,0 @@ -# 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. diff --git a/samples/databases/wide-world-importers/documentation/wwi-olap-sample-queries.md b/samples/databases/wide-world-importers/documentation/wwi-olap-sample-queries.md index 72f6c331..62a23a28 100644 --- a/samples/databases/wide-world-importers/documentation/wwi-olap-sample-queries.md +++ b/samples/databases/wide-world-importers/documentation/wwi-olap-sample-queries.md @@ -1,4 +1,4 @@ -# Documentation for the WideWorldImporters Sample Database +# WideWorldImportersDW OLAP Sample Queries This folder contains documentation for the sample. diff --git a/samples/databases/wide-world-importers/documentation/wwi-olap-sql-features.md b/samples/databases/wide-world-importers/documentation/wwi-olap-sql-features.md index 72f6c331..861706d4 100644 --- a/samples/databases/wide-world-importers/documentation/wwi-olap-sql-features.md +++ b/samples/databases/wide-world-importers/documentation/wwi-olap-sql-features.md @@ -1,4 +1,4 @@ -# Documentation for the WideWorldImporters Sample Database +# WideWorldImportersDW Use of SQL Server Features and Capabilities This folder contains documentation for the sample. diff --git a/samples/databases/wide-world-importers/documentation/wwi-oltp-htap-catalog.md b/samples/databases/wide-world-importers/documentation/wwi-oltp-htap-catalog.md index 72f6c331..496a0c50 100644 --- a/samples/databases/wide-world-importers/documentation/wwi-oltp-htap-catalog.md +++ b/samples/databases/wide-world-importers/documentation/wwi-oltp-htap-catalog.md @@ -1,4 +1,4 @@ -# Documentation for the WideWorldImporters Sample Database +# WideWorldImporters Database Catalog This folder contains documentation for the sample. diff --git a/samples/databases/wide-world-importers/documentation/wwi-oltp-htap-installation.md b/samples/databases/wide-world-importers/documentation/wwi-oltp-htap-installation.md index 72f6c331..b3c9af81 100644 --- a/samples/databases/wide-world-importers/documentation/wwi-oltp-htap-installation.md +++ b/samples/databases/wide-world-importers/documentation/wwi-oltp-htap-installation.md @@ -1,7 +1,51 @@ -# Documentation for the WideWorldImporters Sample Database +# WideWorldImporters Installation and Configuration -This folder contains documentation for the sample. +## Prerequisites -Start with [root.md](root.md) +- [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. -Note that these contents will most likely be migrated to MSDN. +## 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 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 recreating the sample will result in slight differences in the data, since there is a random factor in the data generation: + +[wide-world-importers](https://github.com/Microsoft/sql-server-samples/tree/master/samples/databases/wide-world-importers/wwi-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 *WideWorldImporters* 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 Full-Text Indexing. 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 WideWorldImporters database and open a new query window. +2. Run the following T-SQL command to enable the use of Full-Text Indexing in the database: + + EXECUTE Application.Configuration_ApplyFullTextIndexing diff --git a/samples/databases/wide-world-importers/documentation/wwi-oltp-htap-sample-queries.md b/samples/databases/wide-world-importers/documentation/wwi-oltp-htap-sample-queries.md index 72f6c331..f8fccbab 100644 --- a/samples/databases/wide-world-importers/documentation/wwi-oltp-htap-sample-queries.md +++ b/samples/databases/wide-world-importers/documentation/wwi-oltp-htap-sample-queries.md @@ -1,4 +1,4 @@ -# Documentation for the WideWorldImporters Sample Database +# WideWorldImporters Sample Queries This folder contains documentation for the sample. diff --git a/samples/databases/wide-world-importers/documentation/wwi-oltp-htap-sql-features.md b/samples/databases/wide-world-importers/documentation/wwi-oltp-htap-sql-features.md index 72f6c331..3b8915d0 100644 --- a/samples/databases/wide-world-importers/documentation/wwi-oltp-htap-sql-features.md +++ b/samples/databases/wide-world-importers/documentation/wwi-oltp-htap-sql-features.md @@ -1,4 +1,4 @@ -# Documentation for the WideWorldImporters Sample Database +# WideWorldImporters Use of SQL Server Features and Capabilities This folder contains documentation for the sample. diff --git a/samples/databases/wide-world-importers/documentation/wwi-overview.md b/samples/databases/wide-world-importers/documentation/wwi-overview.md index 72f6c331..58b75fb5 100644 --- a/samples/databases/wide-world-importers/documentation/wwi-overview.md +++ b/samples/databases/wide-world-importers/documentation/wwi-overview.md @@ -1,7 +1,53 @@ -# Documentation for the WideWorldImporters Sample Database +# Wide World Importers Overview -This folder contains documentation for the sample. +This is an overview of the fictitious company Wide World Importers and the workflows that are addressed in the WideWorldImporters sample databases for SQL Server and Azure SQL Database. -Start with [root.md](root.md) +Wide World Importers (WWI) is a wholesale novelty goods importer and distributor operating from the San Francisco bay area. -Note that these contents will most likely be migrated to MSDN. +As a wholesaler, WWI’s customers are mostly companies who resell to individuals. WWI sells to retail customers across the United States including specialty stores, supermarkets, computing stores, tourist attraction shops, and some individuals. WWI also sells to other wholesalers via a network of agents who promote the products on WWI’s behalf. While all of WWI’s customers are currently based in the United States, the company is intending to push for expansion into other countries. + +WWI buys goods from suppliers including novelty and toy manufacturers, and other novelty wholesalers. They stock the goods in their WWI warehouse and reorder from suppliers as needed to fulfil customer orders. They also purchase large volumes of packaging materials, and sell these in smaller quantities as a convenience for the customers. + +Recently WWI started to sell a variety of edible novelties such as chilly chocolates. The company previously did not have to handle chilled items. Now, to meet food handling requirements, they must monitor the temperature in their chiller room and any of their trucks that have chiller sections. + +## Workflow for warehouse stock items + +The typical flow for how items are stocked and distributed is as follows: +- WWI creates purchase orders and submits the orders to the suppliers. +- Suppliers send the items, WWI receives them and stocks them in their warehouse. +- Customers order items from WWI +- WWI fills the customer order with stock items in the warehouse, and when they do not have sufficient stock, they order the additional stock from the suppliers. +- Some customers do not want to wait for items that are not in stock. If they order say five different stock items, and four are available, they want to receive the four items and backorder the remaining item. The item would them be sent later in a separate shipment. +- WWI invoices customers for the stock items, typically by converting the order to an invoice. +- Customers might order items that are not in stock. These items are backordered. +- WWI delivers stock items to customers either via their own delivery vans, or via other couriers or freight methods. +- Customers pay invoices to WWI. +- Periodically, WWI pays suppliers for items that were on purchase orders. This is often sometime after they have received the goods. + +## Data Warehouse and analysis workflow + +While the team at WWI use SQL Server Reporting Services to generate operational reports from the WideWorldImporters database, they also need to perform analytics on their data and need to generate strategic reports. The team have created a dimensional data model in a database WideWorldImportersDW. This database is populated by an Integration Services package. + +SQL Server Analysis Services is used to create analytic data models from the data in the dimensional data model. SQL Server Reporting Services is used to generate strategic reports directly from the dimensional data model, and also from the analytic model. Power BI is used to create dashboards from the same data. The dashboards are used on websites, and on phones and tablets. *Note: these data models and reports are not yet available* + +## Additional workflows + +These are additional workflows. +- WWI issues credit notes when a customer does not receive the good for some reason, or when the goods are faulty. These are treated as negative invoices. +- WWI periodically counts the on-hand quantities of stock items to ensure that the stock quantities shown as available on their system are accurate. (The process of doing this is called a stocktake). +- Cold room temperatures. Perishable goods are stored in refrigerated rooms. Sensor data from these rooms is ingested into the database for monitoring and analytics purposes. +- Vehicle location tracking. Vehicles that transport goods for WWI include sensors that track the location. This location is again ingested into the database for monitoring and further analytics. + +## Version of the application + +World Wide Importers has migrated from their previous system to this new SQL Server WWI database system starting January 1, 2013. They migrated to the latest version of SQL Server and started leveraging Azure SQL Database in 2016 to benefit from all the new capabilities. + +## Fiscal year + +The company operates with a financial year that starts on November 1st. + +## Terms of use + +The license for the sample database and the sample code is described here: [license.txt](https://github.com/Microsoft/sql-server-samples/blob/master/license.txt) + +The sample database includes public data that has been loaded from data.gov and Natural EarthData. The terms of use are here: [http://www.naturalearthdata.com/about/terms-of-use/](http://www.naturalearthdata.com/about/terms-of-use/) diff --git a/samples/features/in-memory/ticket-reservations/TicketReservations/bin/Release/DeploymentReport.txt b/samples/features/in-memory/ticket-reservations/TicketReservations/bin/Release/DeploymentReport.txt new file mode 100644 index 00000000..be03fc29 --- /dev/null +++ b/samples/features/in-memory/ticket-reservations/TicketReservations/bin/Release/DeploymentReport.txt @@ -0,0 +1,34 @@ +** Warnings + User level transactions are not supported for memory optimized objects. You must disable the 'Include transactional + scripts' deployment option to successfully deploy changes to memory optimized objects. + +** Highlights + Tables that will be rebuilt + None + Clustered indexes that will be dropped + [dbo].[sql_ts_th] on [dbo].[TicketReservationDetail] + Clustered indexes that will be created + None + Possible data issues + The table [dbo].[TicketReservationDetail] is being dropped and re-created since all non-computed columns within the + table have been redefined. + +** User actions + Create + [mod] (Filegroup) + [dbo].[TicketReservationDetail] (Table) + [dbo].[InsertReservationDetails] (Procedure) + Drop + [dbo].[InsertReservationDetails] (Procedure) + [dbo].[sql_ts_th] (Primary Key) + [dbo].[TicketReservationDetail] (Table) + Alter + [dbo].[ReadMultipleReservations] (Procedure) + [dbo].[BatchInsertReservations] (Procedure) + +** Supporting actions + Refresh + [dbo].[Demo_Reset] (Procedure) + +The table [dbo].[TicketReservationDetail] is being dropped and re-created since all non-computed columns within the table have been redefined. + diff --git a/samples/features/in-memory/ticket-reservations/TicketReservations/bin/Release/DeploymentReport_1.txt b/samples/features/in-memory/ticket-reservations/TicketReservations/bin/Release/DeploymentReport_1.txt new file mode 100644 index 00000000..4b7c860c --- /dev/null +++ b/samples/features/in-memory/ticket-reservations/TicketReservations/bin/Release/DeploymentReport_1.txt @@ -0,0 +1,25 @@ +** Warnings + User level transactions are not supported for memory optimized objects. You must disable the 'Include transactional + scripts' deployment option to successfully deploy changes to memory optimized objects. + +** Highlights + Tables that will be rebuilt + None + Clustered indexes that will be dropped + None + Clustered indexes that will be created + None + Possible data issues + None + +** User actions + Drop + [dbo].[InsertReservationDetails] (Procedure) + Create + [dbo].[TicketReservationDetail] (Table) + [dbo].[InsertReservationDetails] (Procedure) + Alter + [dbo].[ReadMultipleReservations] (Procedure) + [dbo].[BatchInsertReservations] (Procedure) + +** Supporting actions diff --git a/samples/features/in-memory/ticket-reservations/TicketReservations/bin/Release/TicketReservations.publish.sql b/samples/features/in-memory/ticket-reservations/TicketReservations/bin/Release/TicketReservations.publish.sql new file mode 100644 index 00000000..d7cd1804 --- /dev/null +++ b/samples/features/in-memory/ticket-reservations/TicketReservations/bin/Release/TicketReservations.publish.sql @@ -0,0 +1,258 @@ +/* +Deployment script for TicketReservations + +This code was generated by a tool. +Changes to this file may cause incorrect behavior and will be lost if +the code is regenerated. +*/ + +GO +SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON; + +SET NUMERIC_ROUNDABORT OFF; + + +GO +:setvar DatabaseName "TicketReservations" +:setvar DefaultFilePrefix "TicketReservations" +:setvar DefaultDataPath "C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\" +:setvar DefaultLogPath "C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\" + +GO +:on error exit +GO +/* +Detect SQLCMD mode and disable script execution if SQLCMD mode is not supported. +To re-enable the script after enabling SQLCMD mode, execute the following: +SET NOEXEC OFF; +*/ +:setvar __IsSqlCmdEnabled "True" +GO +IF N'$(__IsSqlCmdEnabled)' NOT LIKE N'True' + BEGIN + PRINT N'SQLCMD mode must be enabled to successfully execute this script.'; + SET NOEXEC ON; + END + + +GO +PRINT N'Creating [mod]...'; + + +GO +ALTER DATABASE [$(DatabaseName)] + ADD FILEGROUP [mod] CONTAINS MEMORY_OPTIMIZED_DATA; + + +GO +ALTER DATABASE [$(DatabaseName)] + ADD FILE (NAME = [mod_4C0B6475], FILENAME = N'$(DefaultDataPath)$(DefaultFilePrefix)_mod_4C0B6475.mdf') TO FILEGROUP [mod]; + + +GO +IF EXISTS (SELECT 1 + FROM [master].[dbo].[sysdatabases] + WHERE [name] = N'$(DatabaseName)') + BEGIN + ALTER DATABASE [$(DatabaseName)] + SET ANSI_NULLS ON, + ANSI_PADDING ON, + ANSI_WARNINGS ON, + ARITHABORT ON, + CONCAT_NULL_YIELDS_NULL ON, + QUOTED_IDENTIFIER ON, + ANSI_NULL_DEFAULT ON, + CURSOR_DEFAULT LOCAL + WITH ROLLBACK IMMEDIATE; + END + + +GO +IF EXISTS (SELECT 1 + FROM [master].[dbo].[sysdatabases] + WHERE [name] = N'$(DatabaseName)') + BEGIN + ALTER DATABASE [$(DatabaseName)] + SET PAGE_VERIFY NONE, + DISABLE_BROKER + WITH ROLLBACK IMMEDIATE; + END + + +GO +IF EXISTS (SELECT 1 + FROM [master].[dbo].[sysdatabases] + WHERE [name] = N'$(DatabaseName)') + BEGIN + ALTER DATABASE [$(DatabaseName)] + SET MEMORY_OPTIMIZED_ELEVATE_TO_SNAPSHOT = ON + WITH ROLLBACK IMMEDIATE; + END + + +GO +USE [$(DatabaseName)]; + + +GO +/* +The table [dbo].[TicketReservationDetail] is being dropped and re-created since all non-computed columns within the table have been redefined. +*/ + +IF EXISTS (select top 1 1 from [dbo].[TicketReservationDetail]) + RAISERROR (N'Rows were detected. The schema update is terminating because data loss might occur.', 16, 127) WITH NOWAIT + +GO +PRINT N'Dropping [dbo].[InsertReservationDetails]...'; + + +GO +DROP PROCEDURE [dbo].[InsertReservationDetails]; + + +GO +PRINT N'Dropping [dbo].[sql_ts_th]...'; + + +GO +ALTER TABLE [dbo].[TicketReservationDetail] DROP CONSTRAINT [sql_ts_th]; + + +GO +PRINT N'Dropping [dbo].[TicketReservationDetail]...'; + + +GO +DROP TABLE [dbo].[TicketReservationDetail]; + + +GO +PRINT N'Creating [dbo].[TicketReservationDetail]...'; + + +GO +CREATE TABLE [dbo].[TicketReservationDetail] ( + [TicketReservationID] BIGINT NOT NULL, + [TicketReservationDetailID] BIGINT IDENTITY (1, 1) NOT NULL, + [Quantity] INT NOT NULL, + [FlightID] INT NOT NULL, + [Comment] NVARCHAR (1000) NULL, + CONSTRAINT [PK_TicketReservationDetail] PRIMARY KEY NONCLUSTERED ([TicketReservationDetailID] ASC) +) +WITH (MEMORY_OPTIMIZED = ON); + + +GO +PRINT N'Creating [dbo].[InsertReservationDetails]...'; + + +GO +/* +CREATE PROCEDURE InsertReservationDetails(@TicketReservationID int, @LineCount int, @Comment NVARCHAR(1000), @FlightID int) +AS +BEGIN + DECLARE @loop int = 0; + WHILE (@loop < @LineCount) + BEGIN + INSERT INTO dbo.TicketReservationDetail (TicketReservationID, Quantity, FlightID, Comment) + VALUES(@TicketReservationID, @loop % 8 + 1, @FlightID, @Comment); + SET @loop += 1; + END +END +*/ + + +-- natively compiled version of the stored procedure: +CREATE PROCEDURE InsertReservationDetails(@TicketReservationID int, @LineCount int, @Comment NVARCHAR(1000), @FlightID int) +WITH NATIVE_COMPILATION, SCHEMABINDING +as +BEGIN ATOMIC WITH (TRANSACTION ISOLATION LEVEL=SNAPSHOT, LANGUAGE=N'English') + + + DECLARE @loop int = 0; + while (@loop < @LineCount) + BEGIN + INSERT INTO dbo.TicketReservationDetail (TicketReservationID, Quantity, FlightID, Comment) + VALUES(@TicketReservationID, @loop % 8 + 1, @FlightID, @Comment); + SET @loop += 1; + END +END +GO +PRINT N'Altering [dbo].[ReadMultipleReservations]...'; + + +GO +ALTER PROCEDURE ReadMultipleReservations(@ServerTransactions int, @RowsPerTransaction int, @ThreadID int) +AS +BEGIN + DECLARE @tranCount int = 0; + DECLARE @CurrentSeq int = 0; + DECLARE @Sum int = 0; + DECLARE @loop int = 0; + WHILE (@tranCount < @ServerTransactions) + BEGIN + BEGIN TRY + SELECT @CurrentSeq = RAND() * IDENT_CURRENT(N'dbo.TicketReservationDetail') + SET @loop = 0 + BEGIN TRAN + WHILE (@loop < @RowsPerTransaction) + BEGIN + SELECT @Sum += FlightID from dbo.TicketReservationDetail where TicketReservationDetailID = @CurrentSeq - @loop; + SET @loop += 1; + END + COMMIT TRAN + END TRY + BEGIN CATCH + IF XACT_STATE() = -1 + ROLLBACK TRAN + ;THROW + END CATCH + SET @tranCount += 1; + END +END +GO +PRINT N'Altering [dbo].[BatchInsertReservations]...'; + + +GO +-- helper stored procedure to + +ALTER PROCEDURE BatchInsertReservations(@ServerTransactions int, @RowsPerTransaction int, @ThreadID int) +AS +BEGIN + DECLARE @tranCount int = 0; + DECLARE @TS Datetime2; + DECLARE @Char_TS NVARCHAR(23); + DECLARE @CurrentSeq int = 0; + + SET @TS = SYSDATETIME(); + SET @Char_TS = CAST(@TS AS NVARCHAR(23)); + WHILE (@tranCount < @ServerTransactions) + BEGIN + BEGIN TRY + BEGIN TRAN + SET @CurrentSeq = NEXT VALUE FOR TicketReservationSequence ; + EXEC InsertReservationDetails @CurrentSeq, @RowsPerTransaction, @Char_TS, @ThreadID; + COMMIT TRAN + END TRY + BEGIN CATCH + IF XACT_STATE() = -1 + ROLLBACK TRAN + ;THROW + END CATCH + SET @tranCount += 1; + END +END +GO +PRINT N'Refreshing [dbo].[Demo_Reset]...'; + + +GO +EXECUTE sp_refreshsqlmodule N'[dbo].[Demo_Reset]'; + + +GO +PRINT N'Update complete.'; + + +GO diff --git a/samples/features/in-memory/ticket-reservations/TicketReservations/bin/Release/TicketReservations_1.publish.sql b/samples/features/in-memory/ticket-reservations/TicketReservations/bin/Release/TicketReservations_1.publish.sql new file mode 100644 index 00000000..140cf5cf --- /dev/null +++ b/samples/features/in-memory/ticket-reservations/TicketReservations/bin/Release/TicketReservations_1.publish.sql @@ -0,0 +1,171 @@ +/* +Deployment script for TicketReservations + +This code was generated by a tool. +Changes to this file may cause incorrect behavior and will be lost if +the code is regenerated. +*/ + +GO +SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON; + +SET NUMERIC_ROUNDABORT OFF; + + +GO +:setvar DatabaseName "TicketReservations" +:setvar DefaultFilePrefix "TicketReservations" +:setvar DefaultDataPath "C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\" +:setvar DefaultLogPath "C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\" + +GO +:on error exit +GO +/* +Detect SQLCMD mode and disable script execution if SQLCMD mode is not supported. +To re-enable the script after enabling SQLCMD mode, execute the following: +SET NOEXEC OFF; +*/ +:setvar __IsSqlCmdEnabled "True" +GO +IF N'$(__IsSqlCmdEnabled)' NOT LIKE N'True' + BEGIN + PRINT N'SQLCMD mode must be enabled to successfully execute this script.'; + SET NOEXEC ON; + END + + +GO +USE [$(DatabaseName)]; + + +GO +PRINT N'Dropping [dbo].[InsertReservationDetails]...'; + + +GO +DROP PROCEDURE [dbo].[InsertReservationDetails]; + + +GO +PRINT N'Creating [dbo].[TicketReservationDetail]...'; + + +GO +CREATE TABLE [dbo].[TicketReservationDetail] ( + [TicketReservationID] BIGINT NOT NULL, + [TicketReservationDetailID] BIGINT IDENTITY (1, 1) NOT NULL, + [Quantity] INT NOT NULL, + [FlightID] INT NOT NULL, + [Comment] NVARCHAR (1000) NULL, + CONSTRAINT [PK_TicketReservationDetail] PRIMARY KEY NONCLUSTERED ([TicketReservationDetailID] ASC) +) +WITH (MEMORY_OPTIMIZED = ON); + + +GO +PRINT N'Creating [dbo].[InsertReservationDetails]...'; + + +GO +/* +CREATE PROCEDURE InsertReservationDetails(@TicketReservationID int, @LineCount int, @Comment NVARCHAR(1000), @FlightID int) +AS +BEGIN + DECLARE @loop int = 0; + WHILE (@loop < @LineCount) + BEGIN + INSERT INTO dbo.TicketReservationDetail (TicketReservationID, Quantity, FlightID, Comment) + VALUES(@TicketReservationID, @loop % 8 + 1, @FlightID, @Comment); + SET @loop += 1; + END +END +*/ + + +-- natively compiled version of the stored procedure: +CREATE PROCEDURE InsertReservationDetails(@TicketReservationID int, @LineCount int, @Comment NVARCHAR(1000), @FlightID int) +WITH NATIVE_COMPILATION, SCHEMABINDING +as +BEGIN ATOMIC WITH (TRANSACTION ISOLATION LEVEL=SNAPSHOT, LANGUAGE=N'English') + + + DECLARE @loop int = 0; + while (@loop < @LineCount) + BEGIN + INSERT INTO dbo.TicketReservationDetail (TicketReservationID, Quantity, FlightID, Comment) + VALUES(@TicketReservationID, @loop % 8 + 1, @FlightID, @Comment); + SET @loop += 1; + END +END +GO +PRINT N'Altering [dbo].[ReadMultipleReservations]...'; + + +GO +ALTER PROCEDURE ReadMultipleReservations(@ServerTransactions int, @RowsPerTransaction int, @ThreadID int) +AS +BEGIN + DECLARE @tranCount int = 0; + DECLARE @CurrentSeq int = 0; + DECLARE @Sum int = 0; + DECLARE @loop int = 0; + WHILE (@tranCount < @ServerTransactions) + BEGIN + BEGIN TRY + SELECT @CurrentSeq = RAND() * IDENT_CURRENT(N'dbo.TicketReservationDetail') + SET @loop = 0 + BEGIN TRAN + WHILE (@loop < @RowsPerTransaction) + BEGIN + SELECT @Sum += FlightID from dbo.TicketReservationDetail where TicketReservationDetailID = @CurrentSeq - @loop; + SET @loop += 1; + END + COMMIT TRAN + END TRY + BEGIN CATCH + IF XACT_STATE() = -1 + ROLLBACK TRAN + ;THROW + END CATCH + SET @tranCount += 1; + END +END +GO +PRINT N'Altering [dbo].[BatchInsertReservations]...'; + + +GO +-- helper stored procedure to + +ALTER PROCEDURE BatchInsertReservations(@ServerTransactions int, @RowsPerTransaction int, @ThreadID int) +AS +BEGIN + DECLARE @tranCount int = 0; + DECLARE @TS Datetime2; + DECLARE @Char_TS NVARCHAR(23); + DECLARE @CurrentSeq int = 0; + + SET @TS = SYSDATETIME(); + SET @Char_TS = CAST(@TS AS NVARCHAR(23)); + WHILE (@tranCount < @ServerTransactions) + BEGIN + BEGIN TRY + BEGIN TRAN + SET @CurrentSeq = NEXT VALUE FOR TicketReservationSequence ; + EXEC InsertReservationDetails @CurrentSeq, @RowsPerTransaction, @Char_TS, @ThreadID; + COMMIT TRAN + END TRY + BEGIN CATCH + IF XACT_STATE() = -1 + ROLLBACK TRAN + ;THROW + END CATCH + SET @tranCount += 1; + END +END +GO +PRINT N'Update complete.'; + + +GO diff --git a/samples/features/in-memory/ticket-reservations/TicketReservations/dbo/Stored Procedures/InsertReservationDetails.sql b/samples/features/in-memory/ticket-reservations/TicketReservations/dbo/Stored Procedures/InsertReservationDetails.sql index 70324630..56fda959 100644 --- a/samples/features/in-memory/ticket-reservations/TicketReservations/dbo/Stored Procedures/InsertReservationDetails.sql +++ b/samples/features/in-memory/ticket-reservations/TicketReservations/dbo/Stored Procedures/InsertReservationDetails.sql @@ -1,4 +1,4 @@ - +/* CREATE PROCEDURE InsertReservationDetails(@TicketReservationID int, @LineCount int, @Comment NVARCHAR(1000), @FlightID int) AS BEGIN @@ -10,9 +10,9 @@ BEGIN SET @loop += 1; END END +*/ -/* -- natively compiled version of the stored procedure: CREATE PROCEDURE InsertReservationDetails(@TicketReservationID int, @LineCount int, @Comment NVARCHAR(1000), @FlightID int) WITH NATIVE_COMPILATION, SCHEMABINDING @@ -28,4 +28,3 @@ BEGIN ATOMIC WITH (TRANSACTION ISOLATION LEVEL=SNAPSHOT, LANGUAGE=N'English') SET @loop += 1; END END -*/ \ No newline at end of file diff --git a/samples/features/in-memory/ticket-reservations/TicketReservations/dbo/Tables/TicketReservationDetail.sql b/samples/features/in-memory/ticket-reservations/TicketReservations/dbo/Tables/TicketReservationDetail.sql index 9d0d059a..b1e67e9d 100644 --- a/samples/features/in-memory/ticket-reservations/TicketReservations/dbo/Tables/TicketReservationDetail.sql +++ b/samples/features/in-memory/ticket-reservations/TicketReservations/dbo/Tables/TicketReservationDetail.sql @@ -5,10 +5,11 @@ FlightID INT NOT NULL, Comment NVARCHAR (1000), -- disk-based table: +/* CONSTRAINT [PK_TicketReservationDetail] PRIMARY KEY CLUSTERED (TicketReservationDetailID) ); +*/ -/* -- for memory-optimized, replace the last two lines with the following: CONSTRAINT [PK_TicketReservationDetail] PRIMARY KEY NONCLUSTERED (TicketReservationDetailID) ) WITH (MEMORY_OPTIMIZED=ON); @@ -17,4 +18,3 @@ GO -- For SQL Server, include the following filegroup. For Azure DB, leave out the filegroup ALTER DATABASE [$(DatabaseName)] ADD FILEGROUP [mod] CONTAINS MEMORY_OPTIMIZED_DATA -*/ \ No newline at end of file