Let $f:X\rightarrow Y$ be a morphism of schemes. I am trying to understand the diagonal morphism $\delta:X\rightarrow X\times_Y X$ associated with this morphism.
To prove $\delta$ is a (locally)closed embedding, we need to prove that atleast $\delta(X)$ is a (locally)closed in $X\times_YX$.
So, we need to get a description of what is this $\delta(X)$.
Let $a\in \delta(X)$ i.e., $a=\delta(x)$ for some $x\in X$. Then,
- $p(a)=p(\delta(x))=(p\circ \delta)(x)=x$ which implies $a\in p^{-1}(x)$
- $q(a)=q(\delta(x))=(q\circ \delta)(x)=x$ which implies $a\in q^{-1}(x)$
So, $a\in p^{-1}(x)\bigcap q^{-1}(x)$ for some $x\in X$. So, $$\delta(X)\subseteq \bigcup_{x\in X}\left(p^{-1}(x)\bigcap q^{-1}(x)\right)$$ I could not see anything more than this and I am more or less sure that this is not an equality.
Let $\{U_i\}$ be an affine open cover for $Y$ then $\{f^{-1}(U_i)\}$ is an open cover for $X$ and we have $$X\times_Y X=\bigcup_i f^{-1}(U_i)\times_{U_i}f^{-1}(U_i)$$
I guess we need to prove that $\delta(X)$ is closed in $\bigcup f^{-1}(U_i)\times_{U_i}f^{-1}(U_i)$ or that $\delta(X)$ is closed in some subcollection which then says $\delta(X)$ is a locally closed subset of $X\times_Y X$.
Any suggestions are welcome.


You can find a proof here : http://stacks.math.columbia.edu/tag/01KJ .