Pharmacologic pain treatment is common among bariatric patients. Nonsteroid anti-inflammatory drugs (NSAID) are not recommended after Roux-en-Y gastric bypass (RYGB) because of the increased risk of marginal ulceration, but the connection with NSAID is not unambiguous. Examine the association between NSAID exposure and peptic ulcers after primary laparoscopic RYGB and sleeve gastrectomy (SG) respectively. University Hospital, Sweden. Cross-matched data from 3 national registers were used in this retrospective, population-based cohort study of all primary laparoscopic RYGB and SG in Sweden within the period from 2010-2015. NSAID exposure was analyzed with individual data of dispensed daily defined doses (DDD) of NSAID after surgery. Multivariate logistic regression estimated the association between NSAID exposure and peptic ulcers, expressed as odds ratios with 95% confidence intervals adjusted for confounding. Of the 41,380 patients (37,913 RYGB, 3467 SG), 1.8% were diagnosed with peptic ulcers after surgery (RYGB 1.9%, SG .2%). In total, 60% of the patients had been prescribed NSAID during a follow-up period of 4.1 (1.0-7.0) years in median. The adjusted risk odds ratios for NSAID exposure were 1.10 (.88-1.38), 1.43 (1.16-1.76), and 1.52 (1.25-1.84) for >0-30 DDD, >30-100 DDD, and >100 DDD, respectively. In subanalysis, the association was similar for RYGB alone, whereas no association was found for SG. The results of the present study support the notion that continuous NSAID use of ≥30 days is a significant risk factor for the development of peptic ulcers after RYGB, whereas temporary use (<30 days) is not. No association between NSAID exposure and the development of peptic ulcers after SG was identified.