-- 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)
One can then save all the code as a file.
Except some small glitches in the editor, everything went smoothly.
Notes:
1) One can suppose that many or most of the queries created in the previous versions of SQL Server work also in SQL databases. The future and revised posts on such topics are labelled under sql database.
2) During the various tests I got the following error message when trying to create a table:
1) One can suppose that many or most of the queries created in the previous versions of SQL Server work also in SQL databases. The future and revised posts on such topics are labelled under sql database.
2) During the various tests I got the following error message when trying to create a table:
"The external policy action 'Microsoft.Sql/Sqlservers/Databases/Schemas/Tables/Create' was denied on the requested resource."At least in my case all I had to do was to select "SQL Database" instead of "SQL analytics endpoint" in the web editor. Check the top right dropdown below your user information.
[3] For a full least of the available features see [2].
Happy coding!
No comments:
Post a Comment