SCD Type 1 and Type 2 using SQL | Implementation of Slowly Changing Dimensions

Поделиться
HTML-код
  • Опубликовано: 6 сен 2024
  • In this video we will learn how to implement scd type 1 and type 2 using SQL. This will help you build logics using update and insert statement.
    script:
    CREATE TABLE product_stg(
    Product_id INT,
    Product_Name VARCHAR(50),
    Price DECIMAL(9,2)
    );
    CREATE TABLE product_dim(
    Product_id INT primary key,
    Product_Name VARCHAR(50),
    Price DECIMAL(9,2),
    last_update date
    );
    create TABLE product_dim(
    product_key int identity(1,1) primary key,
    Product_id INT,
    Product_Name VARCHAR(50),
    Price DECIMAL(9,2),
    start_date date,
    end_date date
    );
    Zero to hero(Advance) SQL Aggregation:
    • All About SQL Aggregat...
    Most Asked Join Based Interview Question:
    • Most Asked SQL JOIN ba...
    Solving 4 Trick SQL problems:
    • Solving 4 Tricky SQL P...
    Data Analyst Spotify Case Study:
    • Data Analyst Spotify C...
    Top 10 SQL interview Questions:
    • Top 10 SQL interview Q...
    Interview Question based on FULL OUTER JOIN:
    • SQL Interview Question...
    Playlist to master SQL :
    • Complex SQL Questions ...
    Rank, Dense_Rank and Row_Number:
    • RANK, DENSE_RANK, ROW_...
    #sql #dataengineer

Комментарии • 47

  • @macx8360
    @macx8360 4 месяца назад +4

    you wont believe ,i was just learning the same concept from your python course today itself in the morning

  • @ashanair5909
    @ashanair5909 24 дня назад

    If there was a way to love your videos and not just like.. Learning a lot Ankit. Thanks

  • @typing07
    @typing07 Месяц назад +1

    @ankit Bhaiya, Instead of doing manual work by query, We can create insert update trigger also, that will be a good automation work.
    What you say brother.☺

    • @ankitbansal6
      @ankitbansal6  Месяц назад +1

      That will be too much load because it will trigger for each row.

  • @shanthiprabhu2100
    @shanthiprabhu2100 Месяц назад

    Great Ankit, thanks. I am completely new to this concept and its very useful

  • @ankitbhangdia3931
    @ankitbhangdia3931 2 месяца назад

    @ankit bansal: Great job on explaining the concept. qq: Instead of making the end date as forever, will it make sense to keep it as NULL & include another column such as is_current_value which would be a boolean field. When someone wants to track the history in the report, an analyst can simply put the condition for start_date, end_date IS NULL and is_current_value = 'n' to take a look at the previous record or they could query on the start_date, end_date IS NOT NULL and is_current_value ='y'. You could even use an OR operator in the query with the structure I'm proposing. Using forever as the end_date is frowned upon in the data warehousing world IMHO.

  • @Nalaka-Wanniarachchi
    @Nalaka-Wanniarachchi 4 месяца назад

    Great stuff.Must learn one by every data enthusiast.

  • @RoamingSoming
    @RoamingSoming 4 месяца назад

    Great way of explaining SCD types

  • @VaanisToonWorld-rp5xy
    @VaanisToonWorld-rp5xy 2 месяца назад

    you have written ELT as extract tranform and load. It's extract load and tranform

  • @anikethdeshpande8336
    @anikethdeshpande8336 2 месяца назад

    Hi Ankit, great explanation,
    how to handle scenario in scd2 type two, when there are insert, update and delete all together in staging for the same record.
    Assuming we are using cdc to keep track of changes and using cdc info to update the dim tables

    • @sandeepguptha6440
      @sandeepguptha6440 2 месяца назад

      then you need to create one more temp_table while running script by keeping where timestamp in stg_table > max(timestamp) in dim_table to get the only changed records to temp_stg table
      now data is in temp_table (which has only latest records)
      dim_table has old records as of now (we did not performed any transformations yet)
      now follow anikt procedure to keep history track

  • @pradeepyogesh4481
    @pradeepyogesh4481 4 месяца назад

    Very good information and thanks for the content. How to create staging tables in the first place?

  • @apexemperor
    @apexemperor 4 месяца назад

    Needed this video but 6months ago... Bt we did it together in office with a friend that time 😀😺 using sql

  • @deepakj6717
    @deepakj6717 4 месяца назад

    Best video.. Thanks !! If possible pls make videos on SQL performance tuning or launch course.

  • @subhajitdey6806
    @subhajitdey6806 4 месяца назад

    great video ! need more data modelling and data engineering videos man !

  • @aadil8409
    @aadil8409 20 дней назад

    sir, can we implement scd-1 via merge statement. i mean to ask is merge statement is nothing but the scd-1 only?

  • @sravankumar1767
    @sravankumar1767 4 месяца назад

    Superb explanation 👌 👏 👍

  • @gazart8557
    @gazart8557 4 месяца назад

    Yaay just yesterday only I learned this thanks

  • @uditkapadia7104
    @uditkapadia7104 2 месяца назад

    Great Explanation !

  • @veereshk6065
    @veereshk6065 4 месяца назад

    Thank you for creating such quality content.
    I have a question,
    is it possible to implement such SCD2 using merge ? (where update and insert are involved to maintain history, same example as described in video).
    Thanks in advance.

    • @ankitbansal6
      @ankitbansal6  4 месяца назад

      It can be done but merge operation can have performance issues.

  • @anudipray4492
    @anudipray4492 28 дней назад

    1ST TABLE IS UPSERT NOT TRANCATE LOAD RIGHT?

  • @Aditya61515
    @Aditya61515 3 месяца назад

    my question is if we connect the data in power bi desktop so we need to manually do this scd 2 or it will automatically updated

  • @meropahad7537
    @meropahad7537 4 месяца назад

    Thanks for the video Ankit

  • @yuvrajyuvas4730
    @yuvrajyuvas4730 Месяц назад

    Awesome Bro..

  • @vijiinfo
    @vijiinfo 2 месяца назад

    ❤❤❤

  • @nehashahpatel1741
    @nehashahpatel1741 3 месяца назад

    Million Thanks

  • @srinubathina7191
    @srinubathina7191 4 месяца назад

    Thank you Ankit Bro

  • @vamsivamsi2029
    @vamsivamsi2029 4 месяца назад

    Thanks @ankit

  • @007SAMRATROY
    @007SAMRATROY 4 месяца назад +1

    Can't we use merge to perform the SCD2 implementation?

    • @ankitbansal6
      @ankitbansal6  4 месяца назад +4

      Performance is not good with merge.

  • @prashantmhatre9225
    @prashantmhatre9225 Месяц назад

    Not sure what you have not implemented by using merge statement

  • @chinmayaMuduli-kf3dd
    @chinmayaMuduli-kf3dd 4 месяца назад

    Hi Ankit sir will you start any data engineering course ?

  • @milindzuge906
    @milindzuge906 4 месяца назад

    Thank you so much Ankit ❤😊

  • @nupoornawathey100
    @nupoornawathey100 4 месяца назад

    for mysql query is slightly changed:
    set @updated_date='2024-01-20';
    UPDATE product_type1_dim a, product_stg b
    SET a.price = b.price, a.last_update = @updated_date
    WHERE a.product_id = b.product_id ;

  • @sowjanyamasna3313
    @sowjanyamasna3313 4 месяца назад

    Sir which one is first video I learn to this course I start my career plz help me

    • @ankitbansal6
      @ankitbansal6  4 месяца назад

      ruclips.net/video/ejdIgYPfcV4/видео.html

  • @techmania979
    @techmania979 4 месяца назад

    Can’t we use merge statement instead of using two separate insert and update statements???

    • @ankitbansal6
      @ankitbansal6  4 месяца назад +1

      Performance not good with merge

  • @TheSanket148
    @TheSanket148 4 месяца назад

    What if same record comes in staging table,how to handle it?@ankit

    • @ankitbansal6
      @ankitbansal6  4 месяца назад

      That is the case of copy records. We can check if the key and value are the same then ignore them

  • @HumansofChn
    @HumansofChn 4 месяца назад

    Can't we implement it using Merge statemnet

  • @user-bw3gq9dc1e
    @user-bw3gq9dc1e 4 месяца назад

    bro keep the pace slow. You speak too fast

    • @ankitbansal6
      @ankitbansal6  4 месяца назад

      Ok next time. You can reduce speed from settings.

  • @9940114158
    @9940114158 4 месяца назад

    Thank you Ankit