Use This One SQL Command to Insert OR Update a Table

Поделиться
HTML-код
  • Опубликовано: 16 окт 2024

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

  • @paulsilva753
    @paulsilva753 3 месяца назад +2

    Thank you for sharing! It is interesting to know new techniques and functions.

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

      Thanks, glad you enjoyed it!

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

    That was very useful. Thank you.
    So, let's say you want to insert/merge one record. Your plan of action would be:
    -
    1. Create a temporary table and insert the data
    2. Run the MERGE on the target table using field(s) other than ID since to find that for your temp, you would need to find it in the target at which point you will know whether or not you need to insert or update
    3. Drop the temporary table
    -
    I hope I was clear enough on that. So, did I get the plan right?

    • @DatabaseStar
      @DatabaseStar  3 месяца назад +1

      Yeah that sounds like it would work!

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

    Thank you for the wonderful video sir, it is so helpful for me and my team, thanks again sir

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

    If you had used UUIDs for the primary surrogate key, then you wouldn't have the problem of both of them having 5 because the probability of two rows having the same UUID is extremely low. That's why I always use UUIDs.

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

      Good point, that would have avoided this issue. I have a video coming soon on UUIDs that explains this benefit too.

  • @VKY-XLR8
    @VKY-XLR8 2 месяца назад

    Nothing, alternative for mysql then?

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

      Yeah, there's a keyword or technique called INSERT ON DUPLICATE KEY UPDATE which I can make a video about in the future.