11-- WideWorldImporters Database Metadata Population
22--
33-- Creates the WWI_Prep Database
4- --
4+ --
55
66USE master ;
77GO
@@ -76,7 +76,7 @@ CREATE TABLE Metadata.[Constraints]
7676 [ConstraintID] int IDENTITY (1 ,1 )
7777 CONSTRAINT PK_Metadata_Constraints PRIMARY KEY ,
7878 TableName sysname NOT NULL ,
79- ConstraintName sysname NOT NULL ,
79+ ConstraintName sysname NOT NULL ,
8080 ConstraintDefinition nvarchar (max ) NOT NULL ,
8181 ConstraintDescription nvarchar (max ) NOT NULL
8282);
@@ -87,7 +87,7 @@ CREATE TABLE Metadata.[Indexes]
8787 [IndexID] int IDENTITY (1 ,1 )
8888 CONSTRAINT PK_Metadata_Indexes PRIMARY KEY ,
8989 TableName sysname NOT NULL ,
90- IndexName sysname NOT NULL ,
90+ IndexName sysname NOT NULL ,
9191 IndexColumns nvarchar (max ) NOT NULL ,
9292 IncludedColumns nvarchar (max ) NULL ,
9393 IsUnique bit NOT NULL ,
@@ -97,9 +97,9 @@ CREATE TABLE Metadata.[Indexes]
9797GO
9898
9999-- Schemas
100- INSERT Metadata.[Schemas]
100+ INSERT Metadata.[Schemas]
101101 (SchemaName, SchemaDescription)
102- VALUES
102+ VALUES
103103 (N ' Application' , N ' Tables common across the application. Used for categorization and lookup lists, system parameters and people (users and contacts)' ),
104104 (N ' DataLoadSimulation' , N ' Tables and procedures used only during simulated data loading operations' ),
105105 (N ' Integration' , ' Tables and procedures required for integration with the data warehouse' ),
@@ -184,7 +184,7 @@ VALUES
184184 (N ' PaymentMethods' , N ' PaymentMethodName' , 0 , N ' nvarchar' , 0 , 50 , NULL , NULL , 0 , 0 , NULL , NULL , 1 , 0 , NULL , NULL , 0 , NULL , N ' Full name of ways that customers can make payments or that suppliers can be paid' );
185185GO
186186
187- -- Application.People Table
187+ -- Application.People Table
188188INSERT Metadata.[Tables]
189189 (TableCreationOrder, SchemaName, TableName, IncludeTemporalColumns, IncludeModificationTrackingColumns, TableDescription)
190190VALUES (10 , N ' Application' , N ' People' , 1 , 1 , N ' People known to the application (staff, customer contacts, supplier contacts)' );
217217
218218INSERT Metadata.[Indexes]
219219 (TableName, IndexName, IndexColumns, IncludedColumns, IsUnique, FilterClause, IndexDescription)
220- VALUES
220+ VALUES
221221 (N ' People' , N ' IX_Application_People_IsEmployee' , N ' [IsEmployee]' , NULL , 0 , NULL , N ' Allows quickly locating employees' );
222222GO
223223
224224INSERT Metadata.[Indexes]
225225 (TableName, IndexName, IndexColumns, IncludedColumns, IsUnique, FilterClause, IndexDescription)
226- VALUES
226+ VALUES
227227 (N ' People' , N ' IX_Application_People_IsSalesperson' , N ' [IsSalesperson]' , NULL , 0 , NULL , N ' Allows quickly locating salespeople' );
228228GO
229229
230230INSERT Metadata.[Indexes]
231231 (TableName, IndexName, IndexColumns, IncludedColumns, IsUnique, FilterClause, IndexDescription)
232- VALUES
232+ VALUES
233233 (N ' People' , N ' IX_Application_People_FullName' , N ' [FullName]' , NULL , 0 , NULL , N ' Improves performance of name-related queries' );
234234GO
235235
236236INSERT Metadata.[Indexes]
237237 (TableName, IndexName, IndexColumns, IncludedColumns, IsUnique, FilterClause, IndexDescription)
238- VALUES
238+ VALUES
239239 (N ' People' , N ' IX_Application_People_Perf_20160301_05' , N ' [IsPermittedToLogon],[PersonID]' , N ' [FullName], [EmailAddress]' , 0 , NULL , N ' Improves performance of order picking and invoicing' );
240240GO
241241
261261
262262INSERT Metadata.[Indexes]
263263 (TableName, IndexName, IndexColumns, IncludedColumns, IsUnique, FilterClause, IndexDescription)
264- VALUES
264+ VALUES
265265 (N ' StateProvinces' , N ' IX_Application_StateProvinces_SalesTerritory' , N ' [SalesTerritory]' , NULL , 0 , NULL , N ' Index used to quickly locate sales territories' );
266266GO
267267
268- -- Application.SystemParameters Table
268+ -- Application.SystemParameters Table
269269INSERT Metadata.[Tables]
270270 (TableCreationOrder, SchemaName, TableName, IncludeTemporalColumns, IncludeModificationTrackingColumns, TableDescription)
271271VALUES (190 , N ' Application' , N ' SystemParameters' , 0 , 1 , N ' Any configurable parameters for the whole system' );
@@ -304,7 +304,7 @@ VALUES
304304 (N ' TransactionTypes' , N ' TransactionTypeName' , 0 , N ' nvarchar' , 0 , 50 , NULL , NULL , 0 , 0 , NULL , NULL , 1 , 0 , NULL , NULL , 0 , NULL , N ' Full name of the transaction type' );
305305GO
306306
307- -- Purchasing.PurchaseOrderLines Table
307+ -- Purchasing.PurchaseOrderLines Table
308308INSERT Metadata.[Tables]
309309 (TableCreationOrder, SchemaName, TableName, IncludeTemporalColumns, IncludeModificationTrackingColumns, TableDescription)
310310VALUES (250 , N ' Purchasing' , N ' PurchaseOrderLines' , 0 , 1 , N ' Detail lines from supplier purchase orders' );
329329
330330INSERT Metadata.[Indexes]
331331 (TableName, IndexName, IndexColumns, IncludedColumns, IsUnique, FilterClause, IndexDescription)
332- VALUES
332+ VALUES
333333 (N ' PurchaseOrderLines' , N ' IX_Purchasing_PurchaseOrderLines_Perf_20160301_4' , N ' [IsOrderLineFinalized], [StockItemID]' , N ' [OrderedOuters], [ReceivedOuters]' , 0 , NULL , N ' Improves performance of order picking and invoicing' );
334334GO
335335
336- -- Purchasing.PurchaseOrders Table
336+ -- Purchasing.PurchaseOrders Table
337337INSERT Metadata.[Tables]
338338 (TableCreationOrder, SchemaName, TableName, IncludeTemporalColumns, IncludeModificationTrackingColumns, TableDescription)
339339VALUES (220 , N ' Purchasing' , N ' PurchaseOrders' , 0 , 1 , N ' Details of supplier purchase orders' );
@@ -371,7 +371,7 @@ VALUES
371371 (N ' SupplierCategories' , N ' SupplierCategoryName' , 0 , N ' nvarchar' , 0 , 50 , NULL , NULL , 0 , 0 , NULL , NULL , 1 , 0 , NULL , NULL , 0 , NULL , N ' Full name of the category that suppliers can be assigned to' );
372372GO
373373
374- -- Purchasing.Suppliers Table
374+ -- Purchasing.Suppliers Table
375375INSERT Metadata.[Tables]
376376 (TableCreationOrder, SchemaName, TableName, IncludeTemporalColumns, IncludeModificationTrackingColumns, TableDescription)
377377VALUES (200 , N ' Purchasing' , N ' Suppliers' , 1 , 1 , N ' Main entity table for suppliers (organizations)' );
@@ -410,7 +410,7 @@ VALUES
410410 (N ' Suppliers' , N ' PostalPostalCode' , 0 , N ' nvarchar' , 0 , 10 , NULL , NULL , 0 , 0 , NULL , NULL , 0 , 0 , NULL , NULL , 0 , NULL , N ' Postal code for the supplier when sending by mail' );
411411GO
412412
413- -- Purchasing.SupplierTransactions Table
413+ -- Purchasing.SupplierTransactions Table
414414INSERT Metadata.[Tables]
415415 (TableCreationOrder, SchemaName, TableName, IncludeTemporalColumns, IncludeModificationTrackingColumns, TableDescription)
416416VALUES (260 , N ' Purchasing' , N ' SupplierTransactions' , 0 , 1 , N ' All financial transactions that are supplier-related' );
438438
439439INSERT Metadata.[Indexes]
440440 (TableName, IndexName, IndexColumns, IncludedColumns, IsUnique, FilterClause, IndexDescription)
441- VALUES
441+ VALUES
442442 (N ' SupplierTransactions' , N ' IX_Purchasing_SupplierTransactions_IsFinalized' , N ' [IsFinalized]' , NULL , 0 , NULL , N ' Index used to quickly locate unfinalized transactions' );
443443GO
444444
@@ -472,7 +472,7 @@ VALUES
472472 (N ' CustomerCategories' , N ' CustomerCategoryName' , 0 , N ' nvarchar' , 0 , 50 , NULL , NULL , 0 , 0 , NULL , NULL , 1 , 0 , NULL , NULL , 0 , NULL , N ' Full name of the category that customers can be assigned to' );
473473GO
474474
475- -- Sales.Customers Table
475+ -- Sales.Customers Table
476476INSERT Metadata.[Tables]
477477 (TableCreationOrder, SchemaName, TableName, IncludeTemporalColumns, IncludeModificationTrackingColumns, TableDescription)
478478VALUES (210 , N ' Sales' , N ' Customers' , 1 , 1 , N ' Main entity tables for customers (organizations or individuals)' );
515515
516516INSERT Metadata.[Indexes]
517517 (TableName, IndexName, IndexColumns, IncludedColumns, IsUnique, FilterClause, IndexDescription)
518- VALUES
518+ VALUES
519519 (N ' Customers' , N ' IX_Sales_Customers_Perf_20160301_06' , N ' [IsOnCreditHold], [CustomerID], [BillToCustomerID]' , N ' [PrimaryContactPersonID]' , 0 , NULL , N ' Improves performance of order picking and invoicing' );
520520GO
521521
@@ -557,7 +557,7 @@ VALUES (N'SpecialDeals', N'CK_Sales_SpecialDeals_Unit_Price_Deal_Requires_Specia
557557 N ' Ensures that if a specific price is allocated that it applies to a specific stock item' );
558558GO
559559
560- -- Sales.CustomerTransactions Table
560+ -- Sales.CustomerTransactions Table
561561INSERT Metadata.[Tables]
562562 (TableCreationOrder, SchemaName, TableName, IncludeTemporalColumns, IncludeModificationTrackingColumns, TableDescription)
563563VALUES (360 , N ' Sales' , N ' CustomerTransactions' , 0 , 1 , N ' All financial transactions that are customer-related' );
584584
585585INSERT Metadata.[Indexes]
586586 (TableName, IndexName, IndexColumns, IncludedColumns, IsUnique, FilterClause, IndexDescription)
587- VALUES
587+ VALUES
588588 (N ' CustomerTransactions' , N ' IX_Sales_CustomerTransactions_IsFinalized' , N ' [IsFinalized]' , NULL , 0 , NULL , N ' Allows quick location of unfinalized transactions' );
589589GO
590590
591- -- Sales.InvoiceLines Table
591+ -- Sales.InvoiceLines Table
592592INSERT Metadata.[Tables]
593593 (TableCreationOrder, SchemaName, TableName, IncludeTemporalColumns, IncludeModificationTrackingColumns, TableDescription)
594594VALUES (370 , N ' Sales' , N ' InvoiceLines' , 0 , 1 , N ' Detail lines from customer invoices' );
@@ -612,7 +612,7 @@ VALUES
612612 (N ' InvoiceLines' , N ' ExtendedPrice' , 0 , N ' decimal' , 0 , NULL , 18 , 2 , 0 , 0 , NULL , NULL , 0 , 0 , NULL , NULL , 0 , NULL , N ' Extended line price charged' );
613613GO
614614
615- -- Sales.Invoices Table
615+ -- Sales.Invoices Table
616616INSERT Metadata.[Tables]
617617 (TableCreationOrder, SchemaName, TableName, IncludeTemporalColumns, IncludeModificationTrackingColumns, TableDescription)
618618VALUES (310 , N ' Sales' , N ' Invoices' , 0 , 1 , N ' Details of customer invoices' );
650650
651651INSERT Metadata.[Indexes]
652652 (TableName, IndexName, IndexColumns, IncludedColumns, IsUnique, FilterClause, IndexDescription)
653- VALUES
653+ VALUES
654654 (N ' Invoices' , N ' IX_Sales_Invoices_ConfirmedDeliveryTime' , N ' [ConfirmedDeliveryTime]' , N ' [ConfirmedReceivedBy]' , 0 , NULL , N ' Allows quick retrieval of invoices confirmed to have been delivered in a given time period' );
655655GO
656656
@@ -660,7 +660,7 @@ VALUES (N'Invoices', N'CK_Sales_Invoices_ReturnedDeliveryData_Must_Be_Valid_JSON
660660 N ' CHECK (ReturnedDeliveryData IS NULL OR ISJSON(ReturnedDeliveryData) <> 0)' ,
661661 N ' Ensures that if returned delivery data is present that it is valid JSON' );
662662
663- -- Sales.OrderLines Table
663+ -- Sales.OrderLines Table
664664INSERT Metadata.[Tables]
665665 (TableCreationOrder, SchemaName, TableName, IncludeTemporalColumns, IncludeModificationTrackingColumns, TableDescription)
666666VALUES (320 , N ' Sales' , N ' OrderLines' , 0 , 1 , N ' Detail lines from customer orders' );
685685
686686INSERT Metadata.[Indexes]
687687 (TableName, IndexName, IndexColumns, IncludedColumns, IsUnique, FilterClause, IndexDescription)
688- VALUES
688+ VALUES
689689 (N ' OrderLines' , N ' IX_Sales_OrderLines_AllocatedStockItems' , N ' [StockItemID]' , N ' [PickedQuantity]' , 0 , NULL , N ' Allows quick summation of stock item quantites already allocated to uninvoiced orders' );
690690GO
691691
692692INSERT Metadata.[Indexes]
693693 (TableName, IndexName, IndexColumns, IncludedColumns, IsUnique, FilterClause, IndexDescription)
694- VALUES
694+ VALUES
695695 (N ' OrderLines' , N ' IX_Sales_OrderLines_Perf_20160301_01' , N ' [PickingCompletedWhen], [OrderID], [OrderLineID]' , N ' [Quantity], [StockItemID]' , 0 , NULL , N ' Improves performance of order picking and invoicing' );
696696GO
697697
698698INSERT Metadata.[Indexes]
699699 (TableName, IndexName, IndexColumns, IncludedColumns, IsUnique, FilterClause, IndexDescription)
700- VALUES
700+ VALUES
701701 (N ' OrderLines' , N ' IX_Sales_OrderLines_Perf_20160301_02' , N ' [StockItemID], [PickingCompletedWhen]' , N ' [OrderID], [PickedQuantity]' , 0 , NULL , N ' Improves performance of order picking and invoicing' );
702702GO
703703
704- -- Sales.Orders Table
704+ -- Sales.Orders Table
705705INSERT Metadata.[Tables]
706706 (TableCreationOrder, SchemaName, TableName, IncludeTemporalColumns, IncludeModificationTrackingColumns, TableDescription)
707707VALUES (230 , N ' Sales' , N ' Orders' , 0 , 1 , N ' Detail of customer orders' );
@@ -745,6 +745,12 @@ VALUES
745745 (N ' ColdRoomTemperatures' , N ' Temperature' , 0 , N ' decimal' , 0 , NULL , 10 , 2 , 0 , 0 , NULL , NULL , 0 , 0 , NULL , NULL , 0 , NULL , N ' Temperature at the time of recording' );
746746GO
747747
748+ INSERT Metadata.[Indexes]
749+ (TableName, IndexName, IndexColumns, IncludedColumns, IsUnique, FilterClause, IndexDescription)
750+ VALUES
751+ (N ' ColdRoomTemperatures' , N ' IX_Warehouse_ColdRoomTemperatures_ColdRoomSensorNumber' , N ' [ColdRoomSensorNumber]' , NULL , 0 , NULL , N ' Allows quickly locating sensors' );
752+ GO
753+
748754-- Warehouse.Colors Table
749755INSERT Metadata.[Tables]
750756 (TableCreationOrder, SchemaName, TableName, IncludeTemporalColumns, IncludeModificationTrackingColumns, TableDescription)
@@ -790,7 +796,7 @@ VALUES
790796 (N ' StockGroups' , N ' StockGroupName' , 0 , N ' nvarchar' , 0 , 50 , NULL , NULL , 0 , 0 , NULL , NULL , 1 , 0 , NULL , NULL , 0 , NULL , N ' Full name of groups used to categorize stock items' );
791797GO
792798
793- -- Warehouse.StockItemHoldings Table
799+ -- Warehouse.StockItemHoldings Table
794800INSERT Metadata.[Tables]
795801 (TableCreationOrder, SchemaName, TableName, IncludeTemporalColumns, IncludeModificationTrackingColumns, TableDescription)
796802VALUES (245 , N ' Warehouse' , N ' StockItemHoldings' , 0 , 1 , N ' Non-temporal attributes for stock items' );
@@ -810,7 +816,7 @@ VALUES
810816 (N ' StockItemHoldings' , N ' TargetStockLevel' , 0 , N ' int' , 0 , NULL , NULL , NULL , 0 , 0 , NULL , NULL , 0 , 0 , NULL , NULL , 0 , NULL , N ' Typical quantity ordered' );
811817GO
812818
813- -- Warehouse.StockItems Table
819+ -- Warehouse.StockItems Table
814820INSERT Metadata.[Tables]
815821 (TableCreationOrder, SchemaName, TableName, IncludeTemporalColumns, IncludeModificationTrackingColumns, TableDescription)
816822VALUES (240 , N ' Warehouse' , N ' StockItems' , 1 , 1 , N ' Main entity table for stock items' );
@@ -845,7 +851,7 @@ VALUES
845851 (N ' StockItems' , N ' SearchDetails' , 0 , N ' AS CONCAT([StockItemName], N'' '' , [MarketingComments])' , 1 , NULL , NULL , NULL , 0 , 0 , NULL , NULL , 0 , 0 , NULL , NULL , 0 , NULL , N ' Combination of columns used by full text search' );
846852GO
847853
848- -- Warehouse.StockItemStockGroups Table
854+ -- Warehouse.StockItemStockGroups Table
849855INSERT Metadata.[Tables]
850856 (TableCreationOrder, SchemaName, TableName, IncludeTemporalColumns, IncludeModificationTrackingColumns, TableDescription)
851857VALUES (350 , N ' Warehouse' , N ' StockItemStockGroups' , 0 , 1 , N ' Which stock items are in which stock groups' );
@@ -868,7 +874,7 @@ VALUES
868874 (N ' StockItemStockGroups' , N ' UQ_StockItemStockGroups_StockGroupID_Lookup' , N ' UNIQUE(StockGroupID, StockItemID)' , N ' Enforces uniqueness and indexes one side of the many to many relationship' );
869875GO
870876
871- -- Warehouse.StockItemTransactions Table
877+ -- Warehouse.StockItemTransactions Table
872878INSERT Metadata.[Tables]
873879 (TableCreationOrder, SchemaName, TableName, IncludeTemporalColumns, IncludeModificationTrackingColumns, TableDescription)
874880VALUES (380 , N ' Warehouse' , N ' StockItemTransactions' , 0 , 1 , N ' Transactions covering all movements of all stock items' );
@@ -927,7 +933,7 @@ AS BEGIN
927933 DECLARE @StringToExecute nvarchar (max ) = N ' ' ;
928934 DECLARE @NextLineEnd int ;
929935 DECLARE @Counter int ;
930-
936+
931937 WHILE LEN (@StringToPrint) > 0
932938 BEGIN
933939 SET @NextLineEnd = CHARINDEX (NCHAR (13 ), @StringToPrint, 1 );
0 commit comments