Let $f:X \to Y$ a closed immersion of schemes. I want to see why the morphism $: X \times_Y Z \to Z$ induced by the base change $g: Z \to Y$ is also a closed immersion. Here the diagram:
$$\require{AMScd} $$\begin{CD} X \times_Y Z @>>> Z\\ @VVV @VV{g}V \\ X @>f>> Y \end{CD}
My attempts: I heard that it suffice to assume the affine case: So that $X =Spec(R), Y =Spec(S), Z =Spec(A)$
$$\require{AMScd} \begin{CD} R \otimes_S A @<<< A\\ @AAA @AAA \\ R @<<< S \end{CD}$$
By assumption $S \to R$ is surjective. Does it suffice, to prove that $A \to R \otimes_S A$ is also surjective? Why?
And secondly: Why it is a local problem? Therefore why it suffice to consider the affine case?
Background of my question is following former thread of mine: Graph Morphism Closed Immersion
There I wanted to show that for a morphism $f: X \to Y$ where $Y$ is a separated $S$-scheme, the graph morphism $\Gamma_f = (id,f): X \to X \times_S Y$ is a closed immersion.
Following a hint I reduced the problem via
\require{AMScd} \begin{CD} X @>\Gamma_f >> Y\times_S X \\ @VVfV @VV(id,f)V \\ Y @>\Delta>> X \times_S Y \end{CD}
to the current one.