We present the results of targeted searches for gravitational-wave transients associated with gamma-ray bursts during the second observing run of Advanced LIGO and Advanced Virgo, which took place from 2016 November to 2017 August. We have analyzed 98 gamma-ray bursts using an unmodeled search method that searches for generic transient gravitational waves and 42 with a modeled search method that targets compact-binary mergers as progenitors of short gamma-ray bursts. Both methods clearly detect the previously reported binary merger signal GW170817, with p-values of $<9.38 times 10^{-6}$ (modeled) and $3.1 times 10^{-4}$ (unmodeled). We do not find any significant evidence for gravitational-wave signals associated with the other gamma-ray bursts analyzed, and therefore we report lower bounds on the distance to each of these, assuming various source types and signal morphologies. Using our final modeled search results, short gamma-ray burst observations, and assuming binary neutron star progenitors, we place bounds on the rate of short gamma-ray bursts as a function of redshift for $z leq 1$. We estimate 0.07-1.80 joint detections with Fermi-GBM per year for the 2019-20 LIGO-Virgo observing run and 0.15-3.90 per year when current gravitational-wave detectors are operating at their design sensitivities.