SQL01 - Introduction To Business Intelligence
SQL01 - Introduction To Business Intelligence
Business Intelligence
Prem Shanker
Sr. Software Engineer Credit Suisse
Goals
Learn about the concept of Data Warehousing and what BIDS offer. Learn about how to design and implement a Data Warehouse Dimensional database. Learn about what is a cube. Learn about the SQL Server Analysis Services Architecture Learn what is new in Analysis Services 2008 Learn about what is a MDX Language.
Cubes
Analysis Services
Clients
Query Data
Data Warehouse
Table and Cube Star Schema and Snowflake Schema Fact Table and Dimension Table
Table vs Cube
A simplified example:
A typical relational table
Data are organized by rows
Sales table
Product Donut Donut Milk Milk Region East West East West Sales $ 1 2
Region dim
East West Total
Donut Milk
1 3
4
2 4
6
3 7
10
3 Total 4
Product dim
Star Schema
A Star Schema contains a fact table and one or more dimension tables. 1. A Fact Table: The central fact table store the numeric fact (measures) such as Sales dollars, Costs, Unit Sales etc. 2. Dimension Tables: They surround the central fact table, and they store descriptive information about the measures The shape looks like a Star
Star schema
Snowflake Schema
Analysis Server
IIS
XMLA AMO
MOSS
BIDS SSMS ADOMD .NET SSRS
HTTP
Product
Donut
Sandwich
The Sales$ by Soda by West in Yr of 2001
Region
North South East West 1999 2000 2001 2002
Time
Milk Soda
Beer
Demo
Dimension
All dimensions are based on tables or views in a data source view. All dimensions are shared since AS 2005 The structure of a dimension is largely driven by the structure of the underlying dimension table or tables. The simplest structure is called a star schema, which is where each dimension is based on a single dimension table that is directly linked to the fact table by a primary key - foreign key relationship.
Dimension Consists of
A dimension consists of:
Attributes that describe the entity User-Defined Hierarchies that organize dimension members in meaningful ways
such as
Store Name Store City Store State Store Country
Attributes
New feature since AS 2005 Containers of dimension members Typically have one-many relationships between attributes in the same dimension: City State, State Country, etc. All attributes implicitly related to the key
Measure Group
In a cube, a measure is the set of values, usually numeric, that are based on a column in the fact table in the cube. A measure group contains one or more or all the measures from a single fact table. It cant contain measures from different fact table.
Cube
A cube is defined by its measures and dimensions.
Inside a Cube
Measures and Measure Groups Dimensions Relationships Calculations Actions Partitions Perspectives
Demo
Dimension Design
Different Dimension Relationships Regular Dimension Relationship Reference Dimension Relationship Fact Dimension Relationship Role Playing Dimension Parent-Child Hierarchy
It is used in a cube more than one time, each time for a different purpose. Each role-playing dimension is joined to a fact table on a different foreign key.
Example, you might add a Time dimension to a cube three times to track the times that
Parent-Child Hierarchy
A parent-child hierarchy is a hierarchy in a standard dimension that contains a parent attribute. A parent attribute describes a self-join, within the same dimension table. Example: Employee Hierarchy An employee is an employee who reports to his/her manager. His manager is an employee as well Employee Key self joins to ParentEmployeeKey
Calculated Member
A Calculated Members is a member of a dimension or a measure group that is defined based on a MDX expression. The value for the member is calculated at runtime. The result values are not stored in the disk.
Named Set
A named set is a MDX expression that returns a set of dimension members. You can define named sets and save them as part of the cube definition. It allows you to reuse the same named set throughout the cube. Typical example: Create a list Top 10 customers based on Sales You can reuse same Top 10 customers in diff queries.
What Is MDX Testing MDX with the Query Tool in SQL Server Management Studio The Basic Elements of an MDX Query
What Is MDX
An Extension of SQL Syntax That: Queries and manipulates multidimensional data in OLAP cubes Defines calculations based on information in the cube Defines and populates local cubes
Not a True Extension Syntax Deviates Significantly from SQL
Background
Select on axis (x), on axis (y), on axis (z) From [cubeName]
2001
Measures
Measures
Default Member
What if I only specify this? (Products.Bikes, Measures.Units) If Times default member is [1997] Ans: (Products.Bikes, Measures.Units, Time.[1997])
Computer Monitor Printer 1997 1998 Time 1999
2000
2001 Measures
Using Braces { }
Braces Denote a Set Braces Can be Omitted when the Set is Unambiguous. In SSAS 2005 / 2008:
SELECT [Ship Date].[Calendar] ON COLUMNS, [Product].[Product Categories] ON ROWS
FROM [Adventure Works]
In AS 2000:
SELECT {[Ship Date].[Calendar]} ON COLUMNS, {[Product].[Product Categories]} ON ROWS FROM [Adventure Works]
Using Brackets [ ]
Brackets Enclose a String Value Necessary for: Field names with spaces: [New York], [Mary Lo] Numbers as field names: [2007], [2008]
Otherwise, the SSAS will treat them as numerous constants
Default Members
Every Dimension has a Default Member Usually the All member is the default member. Default Measures The measures dimension also has a default measure In our sample cube [Adventure Works], the default member for the cube is [Reseller Sales Amount]
Members
You want to query more than a single cell. Use Members function Members function returns the set of members in a dimension, level, or hierarchy.
select [Ship Date].[Calendar] on columns, [Product].[Product Categories].members on rows from [Adventure Works]
Desired result:
AXIS(1)
AXIS(2) AXIS(3) AXIS(4)
ROWS
PAGES SECTIONS CHAPTERS
No Discunt Reseller
2001 2002 2003 2004
[Ship Date].[Calendar]
Expect Result
2001
Demo
Lab MDX Query