Each badge is different, and it's possible that stored procedures and/or triggers are used for some.
For instance, the "nice answer" which gets awarded to answers voted to 10 could be done in a number of ways.
One way would be to use a trigger on each answer upvote. If a new upvote occurs, see if the new total is 10 - if so, award a badge (assuming all the other badge requirements are met). This would allow real-time awarding, but would also be pretty expensive since there are several other checks to be made prior to awarding this badge.
Another would be to run a query every 5 minutes to gather all the answers that have been upvoted in the previous five minutes that were at 9 votes, and are now at 10 votes. This wouldn't require any triggers or stored procedures, and if run as a batch probably would be less overhead than the first option.
How stack exchange implements it is probably interesting, but its very specific to their database schema and site model. Any other implementation is going to be very different depending on the specifics of that implementation's database and model. If you want a better answer, ask the experts on stack overflow what they would do, given a site such as this. You'll have to word it carefully to avoid it being a question about stack exchange, and instead a question about how one might implement a badge process given a certain database schema (otherwise it'll get closed and/or moved here). You might receive surprising insight into how this is done elsewhere.