In this nationwide population-based cohort study, we found that SGLT2 inhibitors were associated with a lower risk of the composite outcome of hospitalization for HF or mortality compared to DPP4 inhibitors in patients with both type 2 diabetes and AF. This evidence concerns the gene SLC5A2 and atrial fibrillation.