*I had [asked something very similar before on math.se](https://math.stackexchange.com/q/1560243) (deleted now) but unfortunately it hadn't received a lot of attention. I decided to re-ask here.*


Let $S$ be a fixed scheme. Is the following true?



> 
> **Theorem(?):** The category of affine schemes over $S$ is contra-equivalent to the category of quasi-coherent $\mathcal{O}\_S$-algebras
> 
> 
> 


Here the category of affine scheme over $S$ is one whose objects are arrows $\operatorname{Spec} A \to S$ where $A$ ranges over all possible rings and whose morphisms are morphisms of schemes above $S$. Here's the construction:


Let $\varphi: \mathcal{O}\_S \to \mathcal{F}$ be an $\mathcal{O}\_S$-algebra.


1. Let $X$ be the set of all prime ideal sub-sheafs $\mathcal{P} \subset \mathcal{F}$. That is $\mathcal{P}(U)$ is either a prime or a unit on every open set $U \subset S$.
2. Define a topology with open sets of the form $V\_{U,s} = \{\mathcal{P} \in X: s \notin \mathcal{P}(U)\}$ for open sets $U \subset S$ and $s \in \mathcal{F}(U)$.
3. Define the structure sheaf by localizing $\mathcal{O}\_X (V\_{U,s})=\mathcal{F}(U)\_s$.
4. The morphism $X \to S$ that sends a prime sheaf to its pullback by $\varphi$ can be seen to satisfy the requirements.


The inverse functor is the obvious one that sends structure sheafs to their pushforwards.


Recently I found that this equivalence supports a very slick argument that the intersection of affines are affine - which I very much suspect is not true. Here is the (probably false) argument:



> 
> Let $\operatorname{Spec} A \hookrightarrow S$ and $\operatorname{Spec} B \hookrightarrow S$ be affine subschemes. Being affine schemes over $S$ they can be considered as $\mathcal{O}\_S$-algebras. Their intersection is the pullback which corresponds to their tensor product as $\mathcal{O}\_S$-algebras. This gives another $\mathcal{O}\_S$-algebra i.e. an affine scheme over $S$. We're done.
> 
> 
> 


**What are the flaws in the argument/theorem?**



An apparent equivalence of the category of affine schemes over $S$ and the category of quasi-coherent $\mathcal{O}_S$-algebras
No, it's not true in general (EGA 2, (1.2.3)). 


The following example is taken from EGA 2, (1.3.3). Over a field $K$, let $S$ be the affine plane with a doubled origin. Then $S$ is the union of two affine open subsets $Y\_1$ and $Y\_2$, each of them is isomorphic to the affine plane, glued along the complementary subset of their origin. In particular, $Y\_1$ is affine, but the open immersion $j\colon Y\_1\to S$ is not an affine morphism because the inverse image of $Y\_2$ is $Y\_1\cap Y\_2$,
the plane minus the origin, which is not an affine scheme.


On the other hand, if $S$ is separated, then the intersection of two open affine subschemes is affine, and this will imply that your desired result holds true (see EGA 1 (5.5.10)).


Finally, the other direction does not work either: every scheme, be it affine or not, is affine over itself.


