TITLE: effective Cartier divisor is trivial
QUESTION [8 upvotes]: Given a schema $X/k$ with $H^0(X,\mathcal{O}_X^\times) = k^\times$ and an effective Cartier divisor $D \geq 0$ such that $\mathcal{O}(D) = O_X$, why is necessarily $D = 0$?
I tried to apply the long exact cohomology sequence to $1 \to \mathcal{O}_X^\times \to \mathcal{M}_X^\times \to \mathcal{M}_X^\times/\mathcal{O}_X^\times \to 1$, but without success.

REPLY [6 votes]: Edited version. This is true without hypothesis on $H^0(X, \mathcal O_X^{\star})$ and without assuming $D\ge 0$. 
As in Georges's excellent answer, $D$ is defined by an invertible rational function $f$ on $X$. The condition $f^{-1}\mathcal O_X=\mathcal O_X(D)=\mathcal O_X$ then implies that $f$ is regular and invertible in $\mathcal O_X$. So $D=0$ by definition. 
One more edit (sorry). This indeed is an interesting question that we could put in a different perspective. Let $X$ be a noetherian scheme. It is known that the canonical map from the group of Cartier divisors modulo linear equivalence to the Picard group of $X$ is injective (this is what you can prove with your exact sequence $1\to \mathcal O_X^{\star}\to \mathcal M_X^{\star}\to ...$). But there is a more primitive map from the group of Cartier divisors to the group of sub-invertible sheaves of $\mathcal M_X$ defined by $D\mapsto \mathcal O_X(D)$. What is noticed above is that this map is also injective.