Dear Li, first of all I think that when you write "... such that $q \cap B=p$, and $q$ is *the* minimal such ideal in the sense of inclusion", you mean "... and $q$ is *a* minimal ideal...".

The answer to your question is given, I think, by the following more general result

**Theorem** Let $\phi: B\to A$ be a morphism of noetherian rings and ${\frak q} \subset A$ a prime ideal with inverse image ${\frak p}\subset B$. Then we have the following formula
$$dim A_{\frak q}\leq dim B_{\frak p} +dim (A_{\frak q}\otimes_B \kappa(\frak p)) $$

Notice that there is no mention of injectivity for $\phi$ , nor of a field nor of finite generation of $A$ or $B$.

Now, if $\frak q$ happens to be to be -as in your case- the generic point of one of the irreducible components of the fibre at $\frak p$ of the morphism $Spec(\phi): Spec(A) \to Spec(B)$, then the local ring of the fiber at $\frak q$, namely $A_{\frak q}/{\frak p}A_{\frak q} = A_{\frak q}\otimes_B \kappa(\frak p)$, is zero-dimensional (see reminder below) and you get the formula you wished.

**Reminder** The local ring of the generic point of an irreducible scheme is a ring having only one prime ideal (its nilpotent radical) and thus has dimension zero. If the scheme is also reduced, the local ring of its generic point is a field.

**Bibliography**

Matsumura, *Commutative Algebra*, Theorem 19, page 79

Matsumura, *Commutative Ring Theory*, Theorem 15.1, page 116

**An example** In view of Li's comment it might be of interest to some users to see an example.

Let $k$ be a field , $B=k[t]$ and $A=k[t,X,Y]/(t-XY)=k[t,x,y]$. Let $\phi:B\to A$ be the inclusion. Then the fibre of ${\frak p} =(t)\in Spec(B)$ is the subscheme
$F=V(t) \subset Spec(A)$. Please note that, even though $A$ and $B$ are domains, the fibre has two irreducible components with generic points ${\frak q}=(t,x)$ and ${\frak q}'=(t,y)$. The potentially confusing fact is that to the "physical" point $Q={\frak q}$ (say) are associated *two* local ring. On the one hand the local ring of $Q$ in the scheme $Spec(A)$, which is $ \mathcal O_{Spec(A), Q}=A_{{\frak q}}$ $=A_{(t,x)}$ . And on the other the local ring of $Q$ in the scheme $F$, which is $\mathcal O_{F,Q}=A_{{\frak q}}/tA_{{\frak q}}=k(y)$, a field as expected.