Operations are a major precipitating factor for sodium-glucose co-transporter 2 inhibitor (SGLT2i)-associated diabetic ketoacidosis (DKA). This study aimed to investigate the risks of SGLT2i-associated postoperative DKA. We analysed a population-based cohort of patients with type 2 diabetes who underwent operations during 2015-2020. Patients with SGLT2i prescriptions within 6months before operations were assigned to the SGLT2i group, while others were assigned to the control group. Inverse probability treatment weighting with propensity scores was used to balance the baseline covariates. Postoperative DKA was defined as DKA within 30 days postoperatively. Overall, 147,115 subjects were included (3,419 SGLT2i users; 143,696 controls). Preoperative SGLT2i exposure was associated with increased risks of postoperative DKA (incidence=6.40/1,000 person-years; incidence rate ratio [IRR]6.33, 95% confidence interval [CI] 5.57-7.18; p<0.001). Risk factors of SGLT2i-associated postoperative DKA included emergency operation (IRR 24.56, 95% CI 7.42-81.24; p<0.001), preoperative HbA1c ≥8% (IRR 3.10, 95% CI 1.31-7.33; p=0.010) and insulin use (IRR 2.88, 95% CI 1.27-6.51; p=0.011). SGLT2i users who developed postoperative DKA had worse outcomes (invasive mechanical ventilation, dialysis, infections/sepsis, intensive care, and length of hospitalization; p<0.05) than those who did not, although SGLT2i users who developed postoperative DKA had better outcomes than non-SGLT2i users who developed postoperative DKA (p<0.05). The risk of postoperative DKA decreased following the implementation of an automatic electronic health record pop-up alert on perioperative precaution regarding SGLT2i (from IRR 4.06 [95% CI 3.41-4.83] to 2.97 [95% CI 2.41-3.65]; p for interaction=0.020). Preoperative SGLT2i use was associated with increased risks of postoperative DKA in patients with type 2 diabetes. Clinicians could optimize patients' outcomes by appropriate prescription of SGLT2i, while watching out for high-risk features. Implementing automatic electronic health record pop-up alerts may reduce the risk of SGLT2i-associated postoperative DKA.