# Why is the disjoint union of a finite number of affine schemes an affine scheme?

We know that the disjoint union of an infinite number of affine schemes is not an affine scheme since the underlying topological space is not quasi-compact.

But how do you show that the disjoint union of a finite number of affine schemes is an affine scheme? What are the global sections?

The ring of global sections of the disjoint union (coproduct) is the product of the rings of global sections of the individual schemes: $$\bigcup^{\text{disjoint}}_{1\le i\le n} \text{Spec } R_i=\text{Spec }( R_1\times R_2\times \cdots\times R_n).$$
To explain this in more detail: Let $e_j$ be the element of $\hat R:=R_1\times\cdots\times R_n$ with $1$ in the $j$th position and $0$ elsewhere. Then, if $i\ne j$, any prime ideal $\hat P$ in $\hat R$ contains $e_i e_j=0$, so it contains either $e_i$ or $e_j$. Doing this for all pairs $\{i,j\}$ shows you that $\hat P$ must contain all of the $e_i$s except one, so it is of the form $R_1\times\cdots\times R_{i-1}\times P_i\times R_{i+1}\times\cdots\times R_n$, for some prime ideal $P_i$ of $R_i$. This shows that there is a natural correspondence between the points of $\text{Spec } \hat R$ and those of the disjoint union. Now, let $f_1\in R_1$, $\dots$, $f_n\in R_n$. Then the distinguished open set $D_{(f_1,\ldots,f_n)}$ of $\text{Spec } \hat R$ satisfies \begin{eqnarray*} D_{(f_1,\ldots,f_n)}&=&\{\hat P \subseteq \hat R\mid \hat P \text{ prime}, (f_1,\ldots,f_n)\notin \hat P\}\\ &=& \bigcup_{1\le i\le n} \{R_1\times\cdots\times P_i\times \cdots\times R_n\mid P_i \text{ prime}, f_i\notin P_i\}. \end{eqnarray*} Since these sets are a basis for the topology, if you then set $$U_i:=D_{(0,\ldots,0,1,0,\ldots,0)}, \qquad i=1, \dots, n, \ \ \ \text{1 is at the }i\text{th position}$$ this shows that $$\text{Spec } \hat R = U_1\cup\cdots\cup U_n$$ is a partition of the topological space of $\text{Spec } \hat R$ into $n$ disjoint clopen sets, and that the subset topology on each $U_i$ is identical with that of $\text{Spec } R_i$. Therefore, $\text{Spec } \hat R$ is the coproduct of the $\text{Spec } R_i$s in the category of topological spaces.
There is an isomorphism of localizations $${\hat R}_{(f_1,\ldots,f_n)} \cong (R_1)_{f_1}\times\cdots\times (R_n)_{f_n}$$ for which the square $$\begin{array}{ccc} {\hat R}_{(f_1,\ldots,f_n)}&\cong&(R_1)_{f_1}\times\cdots\times(R_n)_{f_n}\\ \downarrow&\ &\downarrow\\ {\hat R}_{(g_1,\ldots,g_n)}&\cong&(R_1)_{g_1}\times\cdots\times(R_n)_{g_n} \end{array}$$ $$(g_1 \in \sqrt{(f_1)}, \ \dots, \ g_n \in \sqrt{(f_n)})$$ commutes. Since the structure sheaf of an affine scheme is assembled from these localizations, this can be used to show that there is an isomorphism $${\cal O}_{\text{Spec } \hat R}(U)\cong \prod_i {\cal O}_{\text{Spec } R_i} (\alpha_i^{-1}(U))$$ for all open sets $U\subseteq \text{Spec } \hat R$, where the map $\alpha_i: \text{Spec } R_i\to U_i$ is the map of topological spaces which sends $\text{Spec } R_i$ onto its homeomorphic image inside $\text{Spec } \hat R$. Also, if $V\subseteq U$, the diagram $$\begin{array}{ccc} {\cal O}_{\text{Spec } \hat R}(U)&\cong&\prod_i {\cal O}_{\text{Spec } R_i} (\alpha_i^{-1}(U))\\ \downarrow{}&&\downarrow{}\\ {\cal O}_{\text{Spec } \hat R}(V)&\cong&\prod_i {\cal O}_{\text{Spec } R_i} (\alpha_i^{-1}(V)) \end{array}$$ commutes. This means that the stalk at each point in each $\text{Spec } R_i$ is isomorphic to the stalk at its image in $\text{Spec } \hat R$.
For each $i=1$, $\dots$, $n$, there is a morphism $\gamma_i: \text{Spec } R_i\to \text{Spec } \hat R$ which comes from the ring homomorphism projecting $\hat R$ onto $R_i$. To show that $\text{Spec } \hat R$ is the coproduct of the $\text{Spec } R_i$s in the category of schemes, you need to show that for any scheme $Z$ and morphisms $\psi_i: \text{Spec } R_i \to Z$, there is a unique morphism $\psi: \text{Spec } \hat R\to Z$ such that $\psi \circ \gamma_i=\psi_i$ for all $i$. Since $\text{Spec } \hat R$ is the disjoint union of the $\text{Spec } R_i$s as topological spaces, the action of $\psi$ on the topology is determined by letting it act as $\psi_i$ on the copy $U_i$ of $\text{Spec } R_i$ in $\text{Spec } \hat R$. Now for any open set $W$ in $Z$, the morphisms $\psi_i$ give you ring homomorphisms from ${\cal O}_Z(W)$ to ${\cal O}_{\text{Spec } R_i}(\psi_i^{-1}(W))$. Using the isomorphism between $\prod_i {\cal O}_{\text{Spec } R_i}(\psi_i^{-1}(W))$ and ${\cal O}_{\text{Spec } \hat R}(\psi^{-1}(W))$, these can be assembled into a ring homomorphism from ${\cal O}_Z(W)$ to ${\cal O}_{\text{Spec } \hat R}( \psi^{-1}(W))$. This produces the desired morphism $\psi$.
Suppoes $\mathrm Spec A_i$, $i=1,2$ are two affine spaces. Note that disjoint union is a co-product in category of set. So in this case, coproduct will be $\mathrm Spec (A_1\times A_2)$.