This paper is concerned with surface enhanced second harmonic generation through delocalized electromagnetic resonances such as surface plasmons or guided waves at bare or coated metallic gratings. The formalisms presented are rigorous in the sense that the groove depth of the grating is not considered as a perturbative parameter. This allows us to show that there exists an optimum groove depth of the grating for which the enhancement of the second harmonic efficiency, as compared to the flat case, is the greatest. Shallow modulated gratings (10 -1) lead to optimum enhancement as high as 105. Emphasis is placed on the effect of the periodicity and of the profile of the grating on this optimum enhancement.