I recently studied about primary ideals of an commutative ring and found the following example : The primary ideals in $\mathbb{Z}$ are $(0)$ and $(p^n)$, where $p$ is prime.
The case $(0)$ is trivial to verify, so we turn to check for $(p^n)$. We know that an ideal $q$ is primary in $R$ iff all zero divisors in $R/q$ are nilpotent. So I checked the following, we have the ring $\mathbb{Z}/(p^n)$, and counted its zero divisors and nilpotents. Clearly number of nilpotents in $\mathbb{Z}/(p^n)$ is $p^{n-1}$. Number of zero-divisors are $\displaystyle p^n-\phi(p^n)=p^n-p^n\bigg(1-\frac{1}{p}\bigg)=p^{n-1}$. So we have number of zero-divisors=number of nilpotents. So $(p^n)$ is primary ideal.
Now I have two questions, first is, is this method can be applied everywhere to check for primary ideals in any commutative ring? Or is there any counterexample that doesn't fit the criteria of the cardinality I mentioned above? Any help is appreciated.
Well, no, most commutative rings you encounter will not be finite. Of course this is going to break down right away for rings with infinitely many zero divisors, since being an infinite subset of an infinite subset doesn't say anything about equality of the two sets.
So, for example,
$\mathbb Q[x,y]/(x^2, xy)$ has infinitely countably many zero divisors and nilpotents, but the sets are not equal ($y$ is a zero divisor that isn't nilpotent.)