0

I have a table T1 in Snowflake that get's truncated and loaded with data weekly. I have to create another table T2 where I should pass all the initial full load from T1 to T2. Then after each week load in T1, T2 table also gets inserted or updated or deleted accordingly.

Kindly give me some sample reference. Thanks.

  • 3
    Use a MERGE statement – NickW Jul 18 '23 at 19:06
  • What's the purpose of T2 if it's just the same data as T1? If you are trying to keep 2 tables in sync, you may want to consider a CLONE or a VIEW. – Mike Walton Jul 19 '23 at 01:59
  • Actually Table 1 data gets refreshed from Production. The data in that table will get purged each time when it gets refreshed. So need to create another table T2 where the data from T1 will get inserted, updated or deleted on each refresh. Additionally I will create two more columns created date and updated date to track the changes. – Devaraj Mani Maran Jul 19 '23 at 08:04
  • How are you identifying deletions? – NickW Jul 19 '23 at 22:29
  • Yes, Nick. As part of my user story they don't need deletion only insert and update. But if you know any solution please explain it will will be helpful for me in future. Thanks. – Devaraj Mani Maran Jul 21 '23 at 09:11
  • Yes - use a MERGE statement: https://docs.snowflake.com/en/sql-reference/sql/merge – NickW Jul 21 '23 at 10:24

0 Answers0