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 $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.[One  might call a commutative ring with only one prime ideal a quasi-field] 

**Bibliography** Matsumura, *Commutative Algebra*, page 79