The exoplanet population characterized by relatively short orbital periods (P < 100 d) around solar-type stars is dominated by super-Earths and sub-Neptunes. However, these planets are missing in our Solar System and the reason behind this absence is still unknown. Two theoretical scenarios invoke the role of Jupiter as the possible culprit: Jupiter may have acted as a dynamical barrier to the inward migration of sub-Neptunes from beyond the water iceline; alternatively, Jupiter may have considerably reduced the inward flux of material (pebbles) required to form super-Earths inside that iceline. Both scenarios predict an anti-correlation between the presence of small planets and that of cold Jupiters in exoplanetary systems. To test that prediction, we homogeneously analyzed the radial-velocity measurements of 38 Kepler and K2 transiting small planet systems gathered over nearly ten years with the HARPS-N spectrograph, as well as publicly available radial velocities collected with other facilities. We used Bayesian differential evolution Markov chain Monte Carlo techniques, which in some cases were coupled with Gaussian process regression to model non-stationary variations due to stellar magnetic activity phenomena. We detected five cold Jupiters in three systems: two in Kepler-68, two in Kepler-454, and a very eccentric one in K2-312. We also found linear trends caused by bound companions in Kepler-93, Kepler-454, and K2-12, with slopes that are still compatible with a planetary mass for outer bodies in the Kepler-454 and K2-12 systems. By using binomial statistics and accounting for the survey completeness, we derived an occurrence rate of 9.3−2.9+7.7% for cold Jupiters with 0.3–13 MJup and 1–10 AU, which is lower but still compatible at 1.3σ with the value measured from radial-velocity surveys for solar-type stars, regardless of the presence or absence of small planets. The sample is not large enough to draw a firm conclusion about the predicted anti-correlation between small planets and cold Jupiters; nevertheless, we found no evidence of previous claims of an excess of cold Jupiters in small planet systems. As an important byproduct of our analyses, we homogeneously determined the masses of 64 Kepler and K2 small planets, reaching a precision better than 5, 7.5, and 10σ for 25, 13, and 8 planets, respectively. Finally, we release the 3661 HARPS-N radial velocities used in this work to the scientific community. These radial-velocity measurements mainly benefit from an improved data reduction software that corrects for subtle prior systematic effects.