surrogate key & slowly changing dimensions
DESCRIPTION
Surrogate Key & Slowly Changing Dimensions. Surrogate Key. Solusi Surrogate Key. SQL Statement. CREATE TABLE negara ( negara_sk int IDENTITY(1,2) PRIMARY KEY, kode_negara varchar (10) NOT NULL, nama_negara varchar (50) NOT NULL, gdp int ) Identity( a,b ) : a : seed b : increment. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/1.jpg)
Surrogate Key & Slowly Changing Dimensions
![Page 2: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/2.jpg)
SURROGATE KEY
![Page 3: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/3.jpg)
![Page 4: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/4.jpg)
Solusi Surrogate Key
![Page 5: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/5.jpg)
SQL Statement
CREATE TABLE negara ( negara_sk int IDENTITY(1,2) PRIMARY KEY, kode_negara varchar(10) NOT NULL, nama_negara varchar(50) NOT NULL, gdp int)• Identity(a,b) :– a : seed– b : increment
![Page 6: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/6.jpg)
• INSERT negara (kode_negara, nama_negara, gdp) VALUES (‘IND’, ‘Indonesia’, 100)
• INSERT negara (kode_negara, nama_negara, gdp) VALUES (‘SGP’, ‘Singapura’, 1000)
• INSERT negara (kode_negara, nama_negara, gdp) VALUES (‘KAN’, ‘Kanada’, 1100)
![Page 7: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/7.jpg)
SELECT nama_negara, gdp FROM negara WHERE gdp > 100
SELECT negara.nama_negara, propinsi.nama_propinsi FROM negara , propinsi WHERE negara.kode_negara = ‘IND’
AND negara.negara_sk = propinsi.negara_sk
![Page 8: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/8.jpg)
SLOWLY CHANGING DIMENSIONS
![Page 9: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/9.jpg)
![Page 10: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/10.jpg)
SCD Type 1 : Correction of Errors
• Contoh : – Perubahan nama customer Michel Romano
menjadi Michael Romano – Perubahan nama customer setelah menikah
(Kristin Daniels menjadi Kristin Samuelson)
![Page 11: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/11.jpg)
![Page 12: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/12.jpg)
SCD Type 2 : Preservation of History
• Contoh : perubahan status customer menjadi married dan perubahan alamat
![Page 13: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/13.jpg)
![Page 14: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/14.jpg)
SCD Type 3 : Tentative Soft Revisions
• Contoh : perubahan alamat customer
![Page 15: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/15.jpg)
![Page 16: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/16.jpg)
SNOWFLAKE SCHEMA
![Page 17: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/17.jpg)
• Snowflake schema : normalisasi tabel dimensi pada Star Schema
• Contoh : – Dimensi Product : • 50.000 products• 500 product brands• 10 product categories
![Page 18: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/18.jpg)
![Page 19: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/19.jpg)
![Page 20: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/20.jpg)
![Page 21: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/21.jpg)
AGGREGATE FACT TABLE
![Page 22: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/22.jpg)
Ukuran Tabel Fakta
![Page 23: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/23.jpg)
300 stores, 500 products per brandFact table penjualan product per store per week• Query involves 1 product, 1 store, 1
week—retrieve/summarize only 1 fact table row• Query involves 1 product, all stores, 1
week—retrieve/summarize 300 fact table rows• Query involves 1 brand, 1 store, 1
week—retrieve/summarize 500 fact table rows• Query involves 1 brand, all stores, 1
year—retrieve/summarize 7,800,000 fact table rows
![Page 24: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/24.jpg)
• Aggregates have fewer rows than the base tables
• Formation of aggregate fact tables is certainly a very effective method to improve query performance
![Page 25: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/25.jpg)
![Page 26: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/26.jpg)
One-Way Aggregates
• Product category by store by date• Product department by store by date• All products by store by date• Territory by product by date• Region by product by date• All stores by product by date• Month by store by product• Quarter by store by product• Year by store by product
![Page 27: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/27.jpg)
![Page 28: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/28.jpg)
Two-Way Aggregates• Product category by territory by date• Product category by region by date• Product category by all stores by date• Product category by month by store• Product category by quarter by store• Product category by year by store• Product department by territory by
date• Product department by region by date• Product department by all stores by
date• Product department by month by
store• Product department by quarter by
store• Product department by year by store• All products by territory by date
• All products by region by date• All products by all stores by date• All products by month by store• All products by quarter by store• All products by year by store• District by month by product• District by quarter by product• District by year by product• Territory by month by product• Territory by quarter by product• Territory by year by product• Region by month by product• Region by quarter by product• Region by year by product• All stores by month by product• All stores by quarter by product• All stores by year by product
![Page 29: Surrogate Key & Slowly Changing Dimensions](https://reader034.vdocuments.mx/reader034/viewer/2022050806/56816204550346895dd2293b/html5/thumbnails/29.jpg)
Three-Way Aggregates• Product category by territory by month• Product department by territory by
month• All products by territory by month• Product category by region by month• Product department by region by
month• All products by region by month• Product category by all stores by month• Product department by all stores by
month• Product category by territory by
quarter• Product department by territory by
quarter• All products by territory by quarter• Product category by region by quarter• Product department by region by
quarter
• All products by region by quarter• Product category by all stores by
quarter• Product department by all stores by
quarter• Product category by territory by year• Product department by territory by
year• All products by territory by year• Product category by region by year• Product department by region by year• All products by region by year• Product category by all stores by year• Product department by all stores by
year• All products by all stores by year