TITLE: Can you form the "spectrum" of a sheaf of algebras?
QUESTION [9 upvotes]: If X is a scheme, we know there is a one-one correspondence between quasi-coherent
sheaves of $\mathcal O_X$-algebras on X and affine morphisms $Y \longrightarrow X$
But what about arbitrary (not necessarily quasi-coherent) sheaves of $\mathcal O_X$-algebras? Do they correspond to schemes $Y\longrightarrow X$?
It seems to me that given a morphism $f:Y\longrightarrow X$ of schemes,
for any $U\subseteq X$, the association $U\mapsto \mathcal O_Y(f^{-1}(U))$
defines a sheaf of $\mathcal O_X$-algebras. That's one direction. Does it not work in the other direction for some reason?

REPLY [9 votes]: You could ask about this in the category of locally ringed spaces, rather than just schemes.  For every locally ringed space $(X,\mathcal{O}_X)$, and for every sheaf $\mathcal{A}$ of $\mathcal{O}_X$-algebras, there is a locally ringed space, $(S,\mathcal{O}_S)$, a morphism of locally ringed spaces, $$(\pi,\pi^\#):(S,\mathcal{O}_S)\to (X,\mathcal{O}_X),$$ and a morphism of $\mathcal{O}_S$-algebras, $\phi:\pi^*\mathcal{A} \to \mathcal{O}_S$, that represents the contravariant functor from the category of locally ringed spaces over $X$ to the category of sets that associates to each morphism of locally ringed spaces, $(f,f^\#):(Y,\mathcal{O}_Y)\to (X,\mathcal{O}_X)$, the set of morphisms of $\mathcal{O}_Y$-algebras, $\psi:f^*\mathcal{A}\to \mathcal{O}_X$.  Of course when $(X,\mathcal{O}_X)$ is a scheme and $\mathcal{A}$ is quasi-coherent, $(S,\mathcal{O}_S)$ is isomorphic (over $X$) to $\textbf{Spec}_X(\mathcal{A})$ as constructed in Hartshorne's book.  In this sense, the locally ringed space $(S,\mathcal{O}_S)$ deserves to be called "Spec".