Adjunction formula for sub varieties of $\mathbb{P}^n$ I am having some trouble in using the adjunction formula to compute the canonical bundle of a hyper surface of degree d in $\mathbb{P}^n$.
My first question is more general and deals with the definition of the line bundle associated to a sub variety. Fix notations: $Y \subset X$ smooth sub variety of dimension $dim(X) - 1$.
Being of codimension one $Y$ is locally given by $Y \cap U = V(f) \cap U$, $f \in \mathcal{O}(U)$ (i.e. for all $p \in Y$ there exists such $U$ that contains $p$). We then define the line bundle $\mathcal{O}(Y)$ to be the one with transition functions $\{f/g \in \mathcal{O}(U \cap V)\}$ if $U \cap V \neq \emptyset$.
What I don't understand is why this construction gives a line bundle over $X$. To define a line bundle over $X$ we need the open sets where the transition functions are defined to be a cover of $X$, but I don't find any reason this should be true. Am I missing something?
Let's focus on $Y = \{ F = 0 \} \subset \mathbb{P}^n$ hyper surface of degree d. I want to use the adjunction formula to compute the canonical bundle of $Y$. I know that:
$K_Y = (K_{\mathbb{P}^n} \otimes \mathcal{O}(Y)) \rvert_Y$, I also know that $K_{\mathbb{P}^n} = \mathcal{O}_{\mathbb{P}^n}(-n-1)$ (the line bundle whose sections are homogenous polynomial of degree -n-1). Putting these things together I get: $K_Y = (\mathcal{O}_{\mathbb{P}^n}(-n-1) \otimes \mathcal{O}(Y)) \rvert_Y$.
I know the answer is $K_Y = \mathcal{O}_{\mathbb{P}^n}(d-n-1) \rvert_Y$, so I am trying to show that $\mathcal{O}_{\mathbb{P}^n}(d) = \mathcal{O}(Y)$.
Suppose $p \in Y$ is such that $p_i \neq 0$ and further suppose that $f_i(z) = F(z_1, \dots, z_{i-1}, 1, z_{i}, \dots, z_n)$ has derivative respect to $z_j$ non zero. Then we know that locally $Y$ is given by:
$$Y \cap U = \{ [z_0 : \dots : z_n] \in \mathbb{P}^n : \frac{z_j}{z_i} = \psi_{i}^j(\frac{z_1}{z_i}, \dots , \frac{z_n}{z_i}) \}$$
Where $\psi_i^j$ is given by the Implicit Function Theorem.
From here I don't know how to go on. I don't see any reason why the transition functions defined via this local interpretation of $Y$ should give rise to $\mathcal{O}_{\mathbb{P}^n}(d)$.
Any help would be very appreciate. Thank you in advance!
 A: Effective Cartier divisors. Let $X$ be an integral variety and $Y\subset X$ a subvariety of codimension one. Then $Y$ is also called an effective Cartier divisor on $X$. "Effective" refers to the fact that $Y$ is an "actual" subvariety (and not just a formal linear combination of cycles), while "Cartier" means locally principal. The latter means the following, as you already know: we can find an open affine cover $(U_i)$ of $X$ such that, whenever $U_i\cap Y$ is nonempty, the closed immersion $U_i\cap Y\hookrightarrow U_i$ is given by the vanishing of a single function $f_i$ on $U_i$, i.e. it corresponds to a surjection $$\mathcal O_X(U_i)\twoheadrightarrow \mathcal O_X(U_i)/(f_i)\qquad\textrm{for some }f_i\in \mathcal O_X(U_i).$$ 
To give a line bundle is the same as to give its transition functions. Let $\{U_i,f_i\}$ be as above. Then we can describe a rank one invertible sheaf by giving the submodule
$$\mathcal O_X(Y)(U_i):=f_i^{-1}\cdot \mathcal O_X(U_i)\subset K(X).$$ 
[I leave it to you to check that $\{U_i,f_i\}$ give the transition functions of this invertible sheaf $\mathcal O_X(Y)$. In other words, $f_i/f_j\in \mathcal O_X^\times (U_i\cap U_j)$ whenever $U_i\cap U_j\neq \emptyset$.] 
Hypersurfaces in $\mathbb P^n$.
If $F\in k[z_0,z_1,\dots,z_n]$ is a homogeneous polynomial and $$Y=\{F=0\}\subset X=\mathbb P^n,\qquad\textrm{where }\deg F=d,$$ then $Y$ is called a hypersurface of degree $d$ in $\mathbb P^n$. In this case $Y$ is not just locally principal, but it is actually principal, because $F=0$ is true globally. Therefore you can choose the rational function $f_i=F$ on every $U_i$. After setting $U_i=\{z_i\neq 0\}$, we have
$$\mathcal O_X(Y)(U_i)=\frac{1}{F}\cdot  k[z_0/z_i,\dots, z_n/z_i]\subset K(\mathbb P^n).$$
Why $\mathcal O_X(Y)=\mathcal O_{\mathbb P^n}(d)$.
The space of global sections $\mathcal O_{\mathbb P^n}(d)(\mathbb P^n)$ coincides with the space of homogeneous polynomials of degree $d$ in the variables $z_0,z_1,\dots,z_n$. Therefore $F$ is an element of this vector space. Recall that $$\mathcal O_{\mathbb P^n}(d)(U_i)=z_i^d\cdot k[z_0/z_i,\dots, z_n/z_i].$$
The restriction $$\mathcal O_{\mathbb P^n}(d)(\mathbb P^n)\to \mathcal O_{\mathbb P^n}(d)(U_i)\qquad\textrm{sends}\qquad F\mapsto \frac{z_i^d}{F}.$$
An isomorphism $$\mathcal O_{\mathbb P^n}(d)(U_i)\,\widetilde{\to}\,\mathcal O_X(Y)(U_i)$$ is given by $z_i^d\cdot h\mapsto \frac{h}{F}$.
