






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!























INSERT INTO customer_dim SELECT NULL , b.customer_number , b.customer_name , b.customer_street_address , b.customer_zip_code , b.customer_city , b.customer_state , CURRENT_DATE , '9999-12-31' FROM customer_dim a , customer_stg b WHERE a.customer_number = b.customer_number AND (a.customer_street_address <> b.customer_street_address) AND EXISTS ( SELECT * FROM customer_dim x WHERE b.customer_number = x.customer_number AND a.expiry_date = SUBDATE(CURRENT_DATE, 1)) AND NOT EXISTS ( SELECT * FROM customer_dim y WHERE b.customer_number = y.customer_number AND y.expiry_date = '9999-12-31') ;
INSERT INTO customer_dim SELECT NULL , customer_number , customer_name , customer_street_address , customer_zip_code , customer_city , customer_state , CURRENT_DATE , '9999-12-31' FROM customer_stg WHERE customer_number NOT IN( SELECT y.customer_number FROM customer_dim x, customer_stg y WHERE x.customer_number = y.customer_number ) ;
Loading Data in Product Dimension TRUNCATE product_stg ; LOAD DATA INFILE 'product.txt' INTO TABLE product_stg FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '' LINES TERMINATED BY '\r\n' IGNORE 1 LINES ( product_code , product_name , product_category ) ;
INSERT INTO product_dim SELECT NULL , b.product_code , b.product_name , b.product_category , CURRENT_DATE , '9999-12-31' FROM product_dim a , product_stg b WHERE a.product_code = b.product_code AND ( a.product_name <> b.product_name OR a.product_category <> b.product_category ) AND EXISTS ( SELECT * FROM product_dim x WHERE b.product_code = x.product_code AND a.expiry_date = SUBDATE(CURRENT_DATE, 1)) AND NOT EXISTS ( SELECT * FROM product_dim y WHERE b.product_code = y.product_code AND y.expiry_date = '9999-12-31') ;
INSERT INTO product_dim SELECT NULL , product_code , product_name , product_category , CURRENT_DATE , '9999-12-31' FROM product_stg WHERE product_code NOT IN( SELECT y.product_code FROM product_dim x, product_stg y WHERE x.product_code = y.product_code ) ;
INSERT INTO sales_order_fact SELECT order_sk , customer_sk , product_sk , date_sk , order_amount FROM source.sales_order a , order_dim b , customer_dim c , product_dim d , date_dim e WHERE a.order_number = b.order_number AND a.customer_number = c.customer_number AND a.order_date >= c.effective_date AND a.order_date <= c.expiry_date AND a.product_code = d.product_code AND a.order_date >= d.effective_date AND a.order_date <= d.expiry_date AND a.order_date = e.date AND a.entry_date = CURRENT_DATE ;
Preparing Data for Testing Regular Population
USE source; INSERT INTO sales_order VALUES (22, 1, 1, '2010-11-29', '2010-11-29', 1000) , (23, 2, 2, '2010-11-29', '2010-11-29', 2000) , (24, 3, 3, '2010-11-29', '2010-11-29', 3000) , (25, 4, 4, '2010-11-29', '2010-11-29', 4000) , (26, 5, 2, '2010-11-29', '2010-11-29', 1000) , (27, 6, 2, '2010-11-29', '2010-11-29', 3000) , (28, 7, 3, '2010-11-29', '2010-11-29', 5000) , (29, 8, 4, '2010-11-29', '2010-11-29', 7000) , (30, 1, 1, '2010-11-29', '2010-11-29', 1000) , (31, 2, 2, '2010-11-29', '2010-11-29', 2000) , (32, 3, 3, '2010-11-29', '2010-11-29', 4000) , (33, 4, 4, '2010-11-29', '2010-11-29', 6000) , (34, 5, 1, '2010-11-29', '2010-11-29', 2500) , (35, 6, 2, '2010-11-29', '2010-11-29', 5000) , (36, 7, 3, '2010-11-29', '2010-11-29', 7500) , (37, 8, 4, '2010-11-29', '2010-11-29', 1000) ;
Confirming Successful Regular Population
Confirming Successful Regular Population(01)