AdventureWorksCTP3 JSON Sample |
New database and samples for AdventureWorks 2016 CTP3 database are published on AdventureWorks Sample Databases and Scripts for SQL Server 2016 CTP3. In SQLServer2016CTP3Samples.zip file (attached in this post) you can find various example scripts that show how to use various features added in SQL Server 2016.
One of the folders in this archive is JSON folder where you can find some JSON example scripts. In this post we will see short description of the files in this folder.
When you download AdventureWorks2016CTP3 database you will notice that there are a lot of new tables with sufixes _json, _temporal_inmemory, etc. These are new tables that are used in example scripts.
For JSON support are added two new tables:
These tables are just copies of the existing Person.Person and Sales.SalesOrderHeader tables. Note that when you install AdventureWorks2016CTP3 database you don't have any JSON data in this table - you will need to run de-normalization script described below to populate tables with JSON data.
In SQLServer2016CTP3Samples.zip (attached) you will find JSON folder with the following content:
These are scripts that show how to use various JSON features in this database. In the following sections we will see short explanations of these scripts.
First script you would need to run is de-normalization script. Even if you don't need de-normalization you will need this script because this is prerequisite for all other scripts.
This script generates JSON data and stores JSON text in new Person.Person_json and Sales.SalesOrder_json tables. In this script you will see SQL statements that perform following actions:
This script shows how you can transform complex relational structure into de-normalized JSON collections.
Also, this script is important because it initializes new JSON tables with the content that is required for all procedures, views, and queries in the sample.
Run this script even if you don't need de-normalization because without this script you will not have JSON column and JSON content in Person.Person_json and Sales.SalesOrder_json tables.
These two files show how you can create stored procedures and views that query and process JSON text in Person.Person_json and Sales.SalesOrder_json tables.
First JSON view Sales.vwSalesOrderItems_json shows how you can create relational "table view" on the array of order items stored in OrderItems in Sales.SalesOrder_json table.
Second JSON view Sales.vwSalesOrderInfo_json returns information about shipping address and method, salesman, and customer from Info JSON column. This view shows how you can encapsulate values in JSON text end expose them as regular columns. If you don't want to use JSON data structures, you also have Sales.vwSalesOrderInfoRel_json view that shows how this query would look in the original relational schema.
JSON procedures shows different use case that you might use for JSON processing such as:
In this file you can see how to create B-tree or full-text search indexes on JSON columns, This file also contains some stored procedures with queries that use new indexes.
Show actual execution plan option in SQL Server Management Studio when you runt these stored procedures to verify that queries use indexes during execution.
In this file you find procedures that export table data from Person.Person_json and Sales.SalesOrder_json tables and import JSON text into these tables. This script demonstrates how easily you can transform relational data to JSON and vice versa.
In this file you find various queries that use views and stored procedures created in previous scripts.
In this file you find script that deletes all new columns, JSON data, stored procedures, indexes, and views that are created in previous steps.
Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |