How to verify if two tables have exactly the same data?

前端 未结 8 688
梦毁少年i
梦毁少年i 2020-12-08 10:34

Basically, we have one table (original table) and it is backed up into another table (backup table); thus the two tables have exactly the same sche

8条回答
  •  粉色の甜心
    2020-12-08 11:28

    select count(*) 
    from lemmas as original_table 
          full join backup_table using (lemma_id)
    where backup_table.lemma_id is null
          or original_table.lemma_id is null
          or original_table.lemma != backup_table.lemma
    

    The full join / check for null should cover additions or deletions as well as changes.

    • backup.id is null = addition
    • original.id is null = deletion
    • neither null = change

提交回复
热议问题