-- tables from SalesLT schema (queries should be run individually) SELECT TOP 100 * FROM SalesLT.Address SELECT TOP 100 * FROM SalesLT.Customer SELECT TOP 100 * FROM SalesLT.CustomerAddress SELECT TOP 100 * FROM SalesLT.Product ITM SELECT TOP 100 * FROM SalesLT.ProductCategory SELECT TOP 100 * FROM SalesLT.ProductDescription SELECT TOP 100 * FROM SalesLT.ProductModel SELECT TOP 100 * FROM SalesLT.ProductModelProductDescription SELECT TOP 100 * FROM SalesLT.SalesOrderDetail SELECT TOP 100 * FROM SalesLT.SalesOrderHeader
-- drop the view (cleaning step)
-- DROP VIEW IF EXISTS SalesLT.vProducts
-- create the view CREATE OR ALTER VIEW SalesLT.vProducts -- Products (view) AS SELECT ITM.ProductID , ITM.ProductCategoryID , PPS.ParentProductCategoryID , ITM.ProductModelID , ITM.Name ProductName , ITM.ProductNumber , PPM.Name ProductModel , PPS.Name ProductSubcategory , PPC.Name ProductCategory , ITM.Color , ITM.StandardCost , ITM.ListPrice , ITM.Size , ITM.Weight , ITM.SellStartDate , ITM.SellEndDate , ITM.DiscontinuedDate , ITM.ModifiedDate FROM SalesLT.Product ITM JOIN SalesLT.ProductModel PPM ON ITM.ProductModelID = PPM.ProductModelID JOIN SalesLT.ProductCategory PPS ON ITM.ProductCategoryID = PPS.ProductCategoryID JOIN SalesLT.ProductCategory PPC ON PPS.ParentProductCategoryID = PPC.ProductCategoryID
-- review the data
SELECT top 100 *FROM SalesLT.vProducts
-- check if all models are available SELECT top 100 ITM.* FROM SalesLT.Product ITM LEFT JOIN SalesLT.ProductModel PPM ON ITM.ProductModelID = PPM.ProductModelID WHERE PPM.ProductModelID IS NULL -- check if all models are available SELECT top 100 ITM.* FROM SalesLT.Product ITM LEFT JOIN SalesLT.ProductCategory PPS ON ITM.ProductCategoryID = PPS.ProductCategoryID WHERE PPS.ProductCategoryID IS NULL -- check if all categories are available SELECT PPS.* FROM SalesLT.ProductCategory PPS LEFT JOIN SalesLT.ProductCategory PPC ON PPS.ParentProductCategoryID = PPC.ProductCategoryID WHERE PPC.ProductCategoryID IS NULL
-- check the hierarchical structure SELECT PPS.ProductCategoryId , PPS.ParentProductCategoryId , PPS.Name ProductCategory , PPC.Name ParentProductCategory FROM SalesLT.ProductCategory PPS LEFT JOIN SalesLT.ProductCategory PPC ON PPS.ParentProductCategoryID = PPC.ProductCategoryID --WHERE PPC.ProductCategoryID IS NULL ORDER BY IsNull(PPC.Name, PPS.Name)
[1] Microsoft Learn (2024) SQL database in Microsoft Fabric (Preview) [link]