Rigorous electromagnetic theory is combined with a phenomenological approach to permit optimization of grating-enhanced second-harmonic generation (SHG) in optical waveguides. Provided that the absorption losses in the optically nonlinear layer are not high, maximum SHG is observed when phase matching occurs between the incident wave at the pump frequency and guided waves at both the pump and the signal frequencies. Different coupling mechanisms are considered, and a procedure for determining the optimal groove depth and period of the grating is discussed. The phenomenological approach permits deeper physical insight into the problem and a considerable saving of computation time. Direct phase matching is shown to result in stronger SHG than indirect phase matching ( performed through the grating vector), even if the former includes coupling between waveguide modes of different orders