Structure sheaf of a locally ringed space can be pulled back from an open cover If I am not mistaken, if $X$ is an algebraic variety and $(U_i)_{i=1}^n$ is an open cover of $X$, to give a regular function $X \to \mathbb{A}^1$ is the same as giving regular functions on the $U_i$ that agree on the intersections. But on the other hand, a regular function on $X$ is just an element of $\mathcal{O}_X(X)$. So does this mean that $X$ as a locally ringed space is equal to the fibered product of the locally ringed spaces $U_i$ along their intersections? Is this fact true in general for (locally) ringed spaces? And why is that so? What would go wrong if I for instance defined $\mathcal{O}_X(X)$ to be smaller (so that not every function that is regular on each $U_i$ belongs to $\mathcal{O}_X(X)$), could I not still get a locally ringed space?
 A: The idea of patching things together from smaller pieces is good, but your guess as to how specifically to do this is not quite correct. One constructs a fiber product $X\times_Z Y$ by having maps $X\to Z$ and $Y\to Z$, but in your case, you have maps $U_i\cap U_j\to U_i$ and $U_j$, which go the wrong way to use a fiber product. Instead, the categorical construction you want to use is a colimit - this correctly describes how to glue things together. 
To be specific, if you have an open covering $\{U_i\}_{i\in I}$ of your locally ringed space, then we can form the poset $\mathcal{P}$ of nonempty finite subsets of $I$ ordered by inclusion, and it is not so hard to show that $\lim_{\rightarrow\mathcal{P}} \bigcap_{i\in p\subset\mathcal{P}} U_i$ is just $X$ (apply the universal property on the topological space side and check the standard sheaf gluing conditions).
The thing that would go wrong if you "defined $\mathcal{O}_X(X)$ to be smaller" is that $\mathcal{O}_X$ would fail to be a sheaf. You would violate the gluing property of sheaves, so $\mathcal{O}_X$ would not be a sheaf, and $(X,\mathcal{O}_X)$ would not be a locally ringed space because $\mathcal{O}_X$ is not a sheaf.
