Lemma 26.6.8. Let $X$ be a locally ringed space. Assume $X = U \amalg V$ with $U$ and $V$ open and such that $U$, $V$ are affine schemes. Then $X$ is an affine scheme.

Proof. Set $R = \Gamma (X, \mathcal{O}_ X)$. Note that $R = \mathcal{O}_ X(U) \times \mathcal{O}_ X(V)$ by the sheaf property. By Lemma 26.6.4 there is a canonical morphism of locally ringed spaces $X \to \mathop{\mathrm{Spec}}(R)$. By Algebra, Lemma 10.21.2 we see that as a topological space $\mathop{\mathrm{Spec}}(\mathcal{O}_ X(U)) \amalg \mathop{\mathrm{Spec}}(\mathcal{O}_ X(V)) = \mathop{\mathrm{Spec}}(R)$ with the maps coming from the ring homomorphisms $R \to \mathcal{O}_ X(U)$ and $R \to \mathcal{O}_ X(V)$. This of course means that $\mathop{\mathrm{Spec}}(R)$ is the coproduct in the category of locally ringed spaces as well. By assumption the morphism $X \to \mathop{\mathrm{Spec}}(R)$ induces an isomorphism of $\mathop{\mathrm{Spec}}(\mathcal{O}_ X(U))$ with $U$ and similarly for $V$. Hence $X \to \mathop{\mathrm{Spec}}(R)$ is an isomorphism. $\square$

In your comment you can use Markdown and LaTeX style mathematics (enclose it like $\pi$). A preview option is available if you wish to see how it works out (just click on the eye in the toolbar).