* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download OLAP Hands
Survey
Document related concepts
Transcript
OLAP Hands-On Lab Phase One: Build the star schema data mart 1. In Query Analyzer, open and execute instnwnd.sql from the install directory where the SQL Server files are installed on your computer. 2. In Query Analyzer, open and execute the northwind_mart3.sql file provided with this demo kit. This TSQL script creates the northwind_mart3 database, 7 data mart tables, and primary and foreign keys. 3. Take a look at the data mart star schema. The best way to do this is with a database diagram. To build the diagram, go to SQL Enterprise Manager, right-click the new northwind_mart3 database, and choose new|database diagram. Step through the new diagram wizard, adding all tables to the diagram. You should see a similar result: 4. Notice the central fact table and the surrounding dimension tables. Notice how the employee table is snowflaked to allow reporting on the regions. Close the diagram and save it if you wish. Phase Two: Populate the Star Schema 1. In SQL Enterprise Manger, right-click the Data Transformation Services folder and choose Open Package. 2. Open the file Populate Northwind_Mart3.dts that is included with this demo kit. If the Select Package dialog box appears, click the Populate Northwind_Mart3 line and choose OK. You should see a similar result: 3. Take some time to explore the DTS package if you wish. It would take too long to explain everything that is happening here, but let’s highlight a few key events. Phase1 of the package begins with a Clear Dimension Tables task. In a realworld solution involving a large OLTP source(s), this would not be the best choice. Phase2 of the package loads the dimension tables of the star schema. The dimension tables must be loaded first since they have a 1-to-many relationship with the fact table. Let’s take a look at a couple of those transformations: i. Double click the arrow between NW-Customer and Northwind_OLAP. ii. Notice how on the destination, the CustomerKey column is skipped. CustomerKey is an artificial primary key called a surrogate key. iii. Close the dialog box and double-click the arrow between NWProduct and Northwind_OLAP. Here is a more complex example of a transformation. In the OLTP source (Northwind), product information is actually stored on 3 tables. iv. Take the time if you want to explore the other dimension transformation scripts. Phase3 of the package loads the fact table. This is the most complicated part of the process. Double-click the arrow between NW-Sales_Fact and Northwind_OLAP. This transformation script is too complicated to discuss here, but the basic idea is that we select all the dimension keys, extract the numeric facts from the OLTP source, and join the results. Certainly, you can expect this to be the most difficult part of your OLAP project. But with a good knowledge of your source data, and some TSQL programming skills, it is nothing to be feared. Often, this is where an organization might request help from an experienced consultant. 4. Close any open dialog boxes. Now, we will execute the DTS package. 5. Exit DTS. Phase Three: Building and Processing the Cube Open Analysis Manger and drill down the console tree until you see the FoodMart 2000 database. 1. If you don’t see your server name under the Analysis Servers folder, you must register your server. Right-click the Analysis Servers folder and choose Register Server to do this. 2. Right-click your server name and choose New Database. Give the database a name of Northwind_Mart3 and choose OK. Your new database should appear under the FoodMart 2000 icon. 3. Now we will create the cube. Expand the Northwind_Mart3, right-click the Cubes folder and choose New Cube|Wizard. 4. Click the New Data Source button. In the list of OLE DB Providers, choose Microsoft OLE DB Provider for SQL Server and then click Next. 5. On the Connection tab, enter your server name, choose Windows NT Integrated security, and select northwind_mart3 as the database. 6. Click the Test Connection button. 7. Choose the Sales_Fact table. Once you have chosen the fact table and clicked Next, it will ask you to identify the numeric and additive measures in your fact table. Double-click Line Item Freight, Line Item Total, Line Item Quantity, and Line Item Discount. 8. Click the Next button to move on. Now the cube wizard wants you to identify your dimensions. Of course, we haven’t built any dimensions yet, so the dialog is empty. Click the New Dimension button to start the Dimension Wizard. 9. At the Dimension Wizard welcome screen, click Next to continue. 10. The first dimension we are going to create is the Customer dimension. It is a standard star schema dimension, so accept the default choice of Star Schema: A single dimension table and click Next. 11. From the list of available tables, double-click Customer_Dim. 12. Once you have selected the Customer_Dim table, click Next to continue. Now it wants you to identify the hierarchy (levels) of the dimension. In other words, define how the user will drill down through the customer data. A natural hierarchy for our customer data is Country, Region, City, Company Name. Page 2 of 4 13. Click the Next button. The Member Key Columns dialog appears, Next to move on. Click Next to move on from here as well. Give the dimension a name of Customer and click Finish. You now have one of our five dimensions completed: 14. Click the New Dimension button again and click Next to move past the Dimension Wizard welcome box. 15. The next dimension we’ll create is the Employee dimension. Recall from our data mart design, that employee information is in two tables: Employee_Dim and Region. Whenever a dimension is built from two or more tables, the design is said to be snowflaked. So choose the snowflake option on the dialog box and click Next to move on. Double-click both the Employee_Dim and Region tables to identify them as the tables from which the dimension will be built. 16. Click Next to continue. The Create and Edit Joins dialog appears showing that the Employee_Dim and Region tables are joined by the RegionID field. Click Next to move on. 17. Now we define the levels of our dimension. This will be similar to how you defined levels for the Customer dimension. Double-click RegionName and EmployeeName to identify the hierarchy. 18. Click the Next button until you get to the final dialog box and then name the dimension Employee. Click the Finish button and now we have two of five dimensions complete. 19. Step through the New Dimension Wizard again to build another dimension with the following specifications: Star Schema, Product_Dim Table , Levels (in this order): CategoryName, ProductName , Name: Product 20. Step through the New Dimension Wizard again to build another dimension with the following specifications: Star Schema Shipper_Dim Table Levels: ShipperName (Yes, only one level) Name: Shipper 21. Finally, star schema and the Time_Dim table. We do, so choose the Time Dimension button and click Next to continue. 22. Once again, we must choose our levels. Since this is a time dimension, the wizard is suggesting a hierarchy of Year, Quarter, Month, Day. Take a look at the other possibilities, but for the purpose of this demo, choose the Year, Quarter, Month, Day option and click Next. 23. Click Next again and then Name the dimension Time. Click Finish. 24. Click the Next button. Click Yes. Name the cube Sales and click Finish. 25. In the cube editor go to the Tools menu and choose Design Storage. The Design Storage wizard appears. Click Next to move on. 26. Choose MOLAP and click Next to move on. You should see the Set Aggregation Options dialog. 27. Click the start button and let the wizard process. 28. Here’s how to read the graph on the right: it would take apprx 0.4MB to store 100% of the possible aggregations (86 total). 29. Click Next to move on. Choose Process Now and click Finish. Page 3 of 4 Congratulations! You are done building and processing the cube. Now you can exit all the way out of Analysis Manger. Phase Four: Browsing The Cube We will use Excel to demonstrate browsing a cube. . 1. Open Excel and get a new spreadsheet. 2. Go to the Data menu and choose Pivot Table and Pivot Chart Report 3. From Step 1 of the PivotTable and PivotChart wizard, choose External Data Source and click Next. 4. Step 2 of the wizard asks Where is your external data stored? Click the Get Data button. 5. You will see a “Choose Data Source” dialog box with three tabs across the top: Databases, Queries, and OLAP cubes. 6. Click New Data Source and choose OK. 7. You are now in the Create New Data Source dialog box. Give your data source a name of Northwind Mart. In the OLAP provider drop-down box, select Microsoft OLE DB Provider for Olap Services 8.0. 8. In the Server box, type the name of your Analysis Server and then click Next. 9. In the next dialog box, choose the Northwind_Mart3 database and click Finish. You should see similar results: 10. Make sure Sales is selected in line 4 and then click OK. 11. Back in the Choose Data Source dialog, click OK again. 12. Now you are back on step 2 of the PivotTable wizard. You should see a message that Data Fields Have Been Retrieved. Click Next. 13. On Step 3 of the PivotTable wizard, click the Finish button. Now let’s build a pivot table with data from our cube! Take the Product label from the toolbar and drag it to the row area. Drag the Time label to the column area. Drag the customer label to the page field area. Finally, drag the LineItemTotal label to the data items area. 14. Now let’s have some fun experimenting with cube browsing. Double-click Beverages in cell A5. Notice how you “drill down” from the category view to the product view. Notice how quickly you get the results (remember that a cube has these aggregates already processed!). If you click a beverage (such as Chai) nothing happens (except an error message) since you can’t drill down any further. Double-click Beverages again to “drill up.” Try drilling down on the year 1997. You should be able to drill down to quarter, month, and day. Try drilling back up. Set your imagination free and keep browsing … Well, there you go. You have only scratched the surface of what a cube can do. There are so many other solutions, like browsing a cube over the web and browsing with advanced analytical software. I hope you see the potential. It is truly amazing how OLAP cubes can revolutionize the way you use your databases. Page 4 of 4