OER UNIT 1 – SCHEMA DESIGN

Slides:



Advertisements
Similar presentations
10 Copyright © 2005, Oracle. All rights reserved. Dimensions.
Advertisements

Dimensional Modeling.
CHAPTER OBJECTIVE: NORMALIZATION THE SNOWFLAKE SCHEMA.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Introduction to Structured Query Language (SQL)
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Database Systems More SQL Database Design -- More SQL1.
A Guide to MySQL 7. 2 Objectives Understand, define, and drop views Recognize the benefits of using views Use a view to update data Grant and revoke users’
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
Oracle Data Definition Language (DDL)
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Concepts of Database Management, Fifth Edition Chapter 4: The Relational Model 3: Advanced Topics.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Fall 2001Database Systems1 Triggers Assertions –Assertions describe rules that should hold for a given database. –An assertion is checked anytime a table.
1 SQL - II Data Constraints –Applying data constraints Types of data constraints –I/O constraints The PRIMARY KEY constraints The FOREIGN KEY constraints.
Oracle 11g: SQL Chapter 4 Constraints.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Session 1 Module 1: Introduction to Data Integrity
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
PRACTICE OVERVIEW PL/SQL Part Your stored procedure, GET_BUDGET, has a logic problem and must be modified. The script that contains the procedure.
IMS 4212: Constraints & Triggers 1 Dr. Lawrence West, Management Dept., University of Central Florida Stored Procedures in SQL Server.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
Murali Mani Constraints. Murali Mani Keys: Primary keys and unique CREATE TABLE Student ( sNum int, sName varchar (20), dept char (2), CONSTRAINT key.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Database Constraints ICT 011. Database Constraints Database constraints are restrictions on the contents of the database or on database operations Database.
Database Constraints Ashima Wadhwa. Database Constraints Database constraints are restrictions on the contents of the database or on database operations.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Getting started with Accurately Storing Data
Fundamentals of DBMS Notes-1.
Fundamental of Database Systems
Prepared By: Bobby Wan Microsoft Access Prepared By: Bobby Wan
More SQL: Complex Queries,
TABLES AND INDEXES Ashima Wadhwa.
Including Constraints
Relational Database Design
SQL: Schema Definition and Constraints Chapter 6 week 6
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
PL/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-1
SQL Creating and Managing Tables
Quiz Questions Q.1 An entity set that does not have sufficient attributes to form a primary key is a (A) strong entity set. (B) weak entity set. (C) simple.
Database Systems Instructor Name: Lecture-12.
OER- UNIT 3 Authorization
SQL Creating and Managing Tables
STRUCTURED QUERY LANGUAGE
Database Security OER- Unit 1-Authentication
What Is a View? EMPNO ENAME JOB EMP Table EMPVU10 View
Database.
SQL Creating and Managing Tables
Teaching slides Chapter 8.
Managing Objects with Data Dictionary Views
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
SQL DATA CONSTRAINTS.
A Guide to SQL, Eighth Edition
Oracle Data Definition Language (DDL)
Oracle9i Developer: PL/SQL Programming Chapter 8 Database Triggers.
Retail Sales is used to illustrate a first dimensional model
Relational Database Design
PRACTICE OVERVIEW PL/SQL Part - 1.
IST 318 Database Administration
Indexes and more Table Creation
-Transactions in SQL -Constraints and Triggers
Presentation transcript:

OER UNIT 1 – SCHEMA DESIGN 1.1 Fact table OER UNIT 1 – SCHEMA DESIGN PART 1 Fact table Dr. Girija Narasimhan

1.1 Fact table DR.GIRIJA NARASIMHAN

OER UNIT 1 – SCHEMA DESIGN PART 2 Dimension table Dr. Girija Narasimhan

1.2 Dimension Table Dimension is a collection of reference information about a measurable in the fact table.  The primary key column of the dimension table has uniquely identifies each dimension record or row. The dimension tables are organized has descriptive attributes.  For example, a customer dimension’s attributes could include first and last name, birth date, gender, Qualification, Address etc., DR.GIRIJA NARASIMHAN

OER UNIT 1 – SCHEMA DESIGN PART 3 Star Schema Dr. Girija Narasimhan

1.3  Star Schema Star Schema a Multidimensional data representation of relational database schema A star schema contains two types of tables – Fact table and dimension table. A Fact table in the middle connected to a set of dimension tables In a star schema, a dimension table will not have any parent table Each dimension table have primary key that corresponds exactly to one of the components of the composite key in the fact table DR.GIRIJA NARASIMHAN

steps of designing star schema  Identify the business process. i.e Fact table For example - sales, reservation 2. Identify the measures or fact data i.e in the sales fact table  net_profit, sales_income, No_of _unit_sold. 3. Identify the Dimension table related to fact table. For example product, Time, Location, Branch 4. List of attributes or column in each dimension table 5.  Find the lowest level of aggregation or summary analysis in the fact table. Ex. Total sales income. DR.GIRIJA NARASIMHAN

DR.GIRIJA NARASIMHAN

Snowflake schema keeps same fact table structure as star schema. Snowflake Schema is a refinement of star schema where some dimensional hierarchy is normalized into third normal form and forms a set of smaller dimension tables.   Snowflake schema keeps same fact table structure as star schema. In the dimension, it has multiple levels with multiple hierarchies. From each hierarchy of levels any one level can be attached to Fact Table. Mostly lowest level hierarchy is attached to Fact Table. These hierarchies help to drill down the data from topmost hierarchies to the lowermost hierarchies. Tables which describe the dimensions will already exist and will typically be normalized. DR.GIRIJA NARASIMHAN

DR.GIRIJA NARASIMHAN

1.3.2. Galaxy schema or Fact cancellation schema   Multiple fact tables share dimension tables. This schema is viewed as collection of stars hence called galaxy schema or fact constellation. Sophisticated application requires such schema. For Data warehouse the fact constellation schema is commonly used since it can model multiple, interrelated subjects. DR.GIRIJA NARASIMHAN

DR.GIRIJA NARASIMHAN

OER UNIT 1 – SCHEMA DESIGN PART 4 CREATE DIMENSION statement Dr. Girija Narasimhan

Before creating dimension, first create  product table as a base table and then create dimension table product_dim. conn  hr/hr Create table product( product_id number(5) primary key,prod_category varchar2(15),product_subcategory varchar2(15),prod_category_desc varchar2(20),Prod_subcate_desc varchar2(20),prod_price number(8,3),prod_status varchar2(5),brand_name varchar2(15),supplier_name varchar2(20)); The SQL CREATE DIMENSION statement supports the specification of levels, hierarchies  and attributes.  DR.GIRIJA NARASIMHAN

CREATE DIMENSION CREATE DIMENSION <DIMENSION_NAME> The SQL CREATE DIMENSION statement supports the specification of levels, hierarchies and attributes. SYNTAX: CREATE DIMENSION <DIMENSION_NAME> LEVEL <LEVEL NAME> IS <TABLE_NAME.COLUMN NAME> HIERARCHY <HIERARCHY NAME> (<CHILD LEVEL_NAME> CHILD OF <PARENT LEVEL_NAME>) ATTRIBUTE <LEVEL NAME> DETERMINES (<COLUMN NAME>) DR.GIRIJA NARASIMHAN

1.5  LEVEL LEVEL is a first part of a Dimension declaration, which involves the specification of levels. All Dimension names are unique in the database, dimension is a database object like table, index, view etc.,  If product_dim is already exist then for adding or modifying level use ALTER dimension otherwise drop dimension product_dim again re-create CREATE DIMENSION product_dim Most dimensions involve multiple levels, in the example there are three Levels namely pid, prod_sub_cate, prod_cate Suppose HR user don't privilege have to create dimension, then grant create dimension privilege to Hr user then create dimension. DR.GIRIJA NARASIMHAN

1.5.1 Identical Level name All the level name in the dimension  to be unique not identical. If both the level has the same  level name. So, it gives error message. DR.GIRIJA NARASIMHAN

1.5.2. Don't repeat the same column as level in different dimension Using same column not allow to create as level even though the dimension is different and level name is different. Therefore only one time the column name of the table is allowed to create dimension. Duplicating the column for level and dimension is not allowed. DR.GIRIJA NARASIMHAN

1.6 Hierarchies Hierarchies are used for data aggregation in data warehousing, it is  logical structures that use ordered levels of organizing data. Example, time dimension, a hierarchy might aggregate data from the month level to the quarter level to the year level. Using hierarchies to drill down into data in the data warehousing to  view different levels of granularity. For example, city is a child of state (because you can aggregate city-level data up to state). A hierarchical relationship is a functional dependency from one level of a hierarchy to the next level in the hierarchy, the CHILD OF relationship denotes that each child's level value is associated with one and only one parent level value If the columns of a parent level and child level are in different relations, then the connection between them also requires a 1:n join relationship Column of each hierarchy level are non-null that hierarchical integrity should be maintained. Hierarchy level cannot be joined to itself either directly or indirectly. DR.GIRIJA NARASIMHAN

A single dimension definition can contain multiple hierarchies. Non-hierarchical dimension are referred as “Flat Dimension”, there is only a single level in a dimension Here, we already created product_dim, so ALTER dimension add hierarchy or otherwise drop dimension product_dim and re-create product_dim again. DR.GIRIJA NARASIMHAN

1.6.1. Hierarchy Using Join key Join key is used in snowflakes schema  for joining parent dimension and child dimension.  Hierarchy level cannot be joined to itself either directly or indirectly. step 1: drop the brand_name from product table because it is normalized into another dimension called brand table alter table product drop column brand_name; step 2: Normalize the product table and create new table brand with three column create table brand(brand_id number(5) primary key, brand_name varchar2(15),brand_desc varchar2(20)); Step 3: Alter the table product and create foreign key relationship between product and brand table.  alter table product  add  brand_id number(5) references brand(brand_id); step 4: create level for brand table primary key DR.GIRIJA NARASIMHAN

step 5: create hierarchy brand_rollup using join key with product brand_id and brand.brand_id DR.GIRIJA NARASIMHAN

1.7 Attributes The ATTRIBUTE clause defines functional dependency relationships involving dimension levels and non source columns in dimension tables. The attribute_clause specify the columns that are uniquely determined by a hierarchy level. There must be a 1:1 attribute relationship between hierarchy levels and their dependent dimension attributes The dependent_columns need not have been specified in the level_clause. For example prod_status is not specified in the level name. ALTER DIMENSION PRODUCT_DIM ADD ATTRIBUTE PID DETERMINES PROD_STATUS;                           OR  ATTRIBUTE PID DETERMINES PRODUCT.PROD_STATUS;  The columns in level must all come from the same table as the dependent_columns. ATTRIBUTE PID DETERMINES BRAND.BRAND_DESC; because level pid from product table but attributes brand_desc  from brand table. DR.GIRIJA NARASIMHAN

1.7.1 Extended_attribute_clause The only difference is that this clause assigns a name to the attribute that is different from the level name. If the extended_attribute_clause is used to create multiple columns determined by a hierarchy level. ALTER DIMENSION PRODUCT_DIM  ADD ATTRIBUTE SUPP LEVEL PID DETERMINES SUPPLIER_NAME; In the above example SUPP is attribute name. DR.GIRIJA NARASIMHAN

1.8.1 Alter Dimension using ADD Add level ALTER DIMENSION PRODUCT_DIM If dimension is already exist then using alter dimension statement it is easy to include hierarchy or level or attributes into the dimension. In the same manner removing or modifying the level, hierarchy or attribute also possible using alter dimension...drop  statement. 1.8.1 Alter Dimension using ADD Add level ALTER DIMENSION PRODUCT_DIM ADD  LEVEL PPRICE IS PRODUCT.PROD_PRICE; Add Hierarchy ADD HIERARCHY PRICE_ROLLUP (PID CHILD OF PROD_CATE CHILD OF PPRICE); Add Attribute ATTRIBUTE psubcate level pid  DETERMINES (product.product_subcategory, Prod_subcate_desc); DR.GIRIJA NARASIMHAN

1.8.2 Alter Dimension using DROP CASCADE and RESTRICT is used for restricting DROP IN ALTER DIMENSION. DR.GIRIJA NARASIMHAN

you can drop one attribute column without dropping them all. The following statement illustrates how you can drop a single column without dropping all columns: ALTER DIMENSION product_dim DROP ATTRIBUTE psubcate LEVEL pid  COLUMN Prod_subcate_desc; 1.9.  DROP Dimension A dimension is removed using the DROP DIMENSION statement. For example: DR.GIRIJA NARASIMHAN

OER UNIT 1 – SCHEMA DESIGN PART 5 Display Dimension 1.1 Fact table OER UNIT 1 – SCHEMA DESIGN PART 5 Display Dimension Dr. Girija Narasimhan

‘DIMENSION’SHOULD BE IN CAPITAL LETTER In the database schema, the dimension is one of the objects like table, index. select object_type, object_name FROM user_objects where object_type='DIMENSION'; ‘DIMENSION’SHOULD BE IN CAPITAL LETTER SQL> SET LINESIZE 400; SQL> select object_type,object_name FROM user_objects where object_type='DIMENSION'; OBJECT_TYPE         OBJECT_NAME ------------------- ----------------------------------------- DIMENSION           PRODUCT_DIM DR.GIRIJA NARASIMHAN

OER UNIT 1 – SCHEMA DESIGN 1.1 Fact table OER UNIT 1 – SCHEMA DESIGN PART 6 Dimension Status Dr. Girija Narasimhan

Select * from all_dimensions; 1.11 Dimension status “All_dimensions” gives the number of dimension created by the user and also tells the status of each dimension table whether it is, ERROR, NEEDS_COMPILE, VALID etc. Select * from all_dimensions; DR.GIRIJA NARASIMHAN

1.13.2 Revalidate Dimension status Suppose after creating the dimension for product table called “product_dim”, alter the structure of the  base table any column data type or size  of the column.  DR.GIRIJA NARASIMHAN

Modify the prod_category varchar2(15) into prod_category varchar2(20); select dimension_name, compile_state from all_dimensions; Alter table product modify (prod_category varchar2(20)); DR.GIRIJA NARASIMHAN

Alter dimension Product_dim compile; To revalidate the dimension “product_dim”, use the COMPILE option; now check the status of dimension again, the status has changed as “VALID” Alter dimension Product_dim compile; select dimension_name, compile_state from all_dimensions; DR.GIRIJA NARASIMHAN

OER UNIT 1 – SCHEMA DESIGN PART 7 Retrieve Dimension 1.1 Fact table OER UNIT 1 – SCHEMA DESIGN PART 7 Retrieve Dimension Dr. Girija Narasimhan

1.12 Retrieve Dimension To view the definition of a dimension, use the DESCRIBE_DIMENSION procedure in the DBMS_DIMENSION package.  it will display how many level, hierarchy and attributes are available within the dimension.  DR.GIRIJA NARASIMHAN

OER UNIT 1 – SCHEMA DESIGN PART 8 Validate Dimension 1.1 Fact table OER UNIT 1 – SCHEMA DESIGN PART 8 Validate Dimension Dr. Girija Narasimhan

1.13 Validate Dimension For verifying the validity of the relationship specified in the dimensions  use DBMS_DIMENSION.VALIDATE_DIMENSION procedure periodically. This procedure is easy to use and has only four parameters:  * Dimension:  who created the dimension or owner of the dimension object  * Incremental: set to TRUE to check only the new rows for tables of this dimension.  * Check nulls: set to TRUE to verify that all columns that are not in the levels containing a SKIP WHEN NULL clauses are not null.  * Statement_id: user-supplied unique identifiers to identify the result of each run of the procedure In this example dimension='hr.product_dim', incremental = FALSE, check_nulls=TRUE, statement_id='error catch' DR.GIRIJA NARASIMHAN

1.13.1 Dimension_Exceptions Before running the VALIDATE_DIMENSION procedure, need to create a local table, DIMENSION_EXCEPTIONS. If the VALIDATE_DIMENSION procedure encounters any errors, the errors are stored in DIMENSION_EXCEPTIONS table.  Querying this table will identify the exceptions that were found.  DR.GIRIJA NARASIMHAN

Step 3: Execute the validate_dimension procedure Step 1: check whether dimension_exception table is exit or not,  then it will be created only once.  Step 2: suppose it is not exist, then create the dimension_exceptions table. create table dimension_exceptions(STATEMENT_ID VARCHAR2(25),OWNER VARCHAR2(25),TABLE_NAME VARCHAR2(20), DIMENSION_NAME   VARCHAR2(25), RELATIONSHIP VARCHAR2(25),BAD_ROWID VARCHAR2(35)); Step 3: Execute the validate_dimension procedure EXECUTE DBMS_DIMENSION.VALIDATE_DIMENSION('hr.product_dim',FALSE, TRUE,'error catch'); Step 4: check there is any error in the dimension exception stored At present, there is no error occurred in the dimension_exceptions table.  DR.GIRIJA NARASIMHAN

Step 5: check with errors Try to insert two records in the base table store. SQL> Insert into product(PRODUCT_ID,PROD_CATEGORY) values (11,'Electronics'); 1 row created. SQL> insert into product (PRODUCT_ID,PROD_CATEGORY) values(11,'Cosmetics'); insert into product (PRODUCT_ID,PROD_CATEGORY) values(11,'Cosmetics') * ERROR at line 1: ORA-00001: unique constraint (HR.SYS_C0011199) violated Select * from dimension_exceptions; DR.GIRIJA NARASIMHAN