|
|||||||||||||||||||||||||||||||||||
|
ExampleRaw SQL is unreadable. For example the statement from Wikipedia article on snowflake schema: SELECT B.Brand, G.Country, SUM (F.Units_Sold) FROM Fact_Sales F INNER JOIN Dim_Date D ON F.Date_Id = D.Id INNER JOIN Dim_Store S ON F.Store_Id = S.Id INNER JOIN Dim_Geography G ON S.Geography_Id = G.Id INNER JOIN Dim_Product P ON F.Product_Id = P.Id INNER JOIN Dim_Product_Category C ON P.Product_Category_Id = C.Id INNER JOIN Dim_Brand B ON P.Brand_Id = B.Id WHERE D.Year = 1997 AND C.Product_Category = 'tv' GROUP BY B.Brand, G.Country
Proper syntax coloring and line breaks make it better. But even a 7-table join it is hard to read. How fast can you spot the error here: SELECT B.Brand, G.Country, SUM (F.Units_Sold) FROM Fact_Sales F INNER JOIN Dim_Date D ON F.Date_Id = D.Id INNER JOIN Dim_Store S ON F.Store_Id = S.Id INNER JOIN Dim_Geography G ON S.Geography_Id = C.Id INNER JOIN Dim_Product P ON F.Product_Id = P.Id INNER JOIN Dim_Product_Category C ON P.Product_Category_Id = C.Id INNER JOIN Dim_Brand B ON P.Brand_Id = B.Id WHERE D.Year = 1997 AND C.Product_Category = 'tv' GROUP BY B.Brand, G.Country
How about this diagram? Can you see the disconnected Geography table and the loop. Yes, S.Geography_Id = G.Id instead of C.id makes more sense. |