How I Survive Undead Invasions
1. Build a bridge just inside the entrance to your fortress, that closes in the direction that blocks the entrance.
2. Build a lever in a busy location.
3. Attach the bridge to the lever.
4. Define the interior of your fortress as a burrow.
5. When undead come calling, sound the civilian alert to bring everyone in.
6. Close the entrance with the bridge.
7. Turn off the alert so that your Dwarves can mine freely.
8. Continue developing your fortress in a sieged state of peaceful enjoyment, until you have a more deadly trap run or an adequate military.
9a. When you are ready, sound the alarm again and then open the bridge. You may need to update your burrow.
9b. A second bridge, controlled by a different lever, can serve as a backstop in case your first "ready" state isn't sufficient.
Addendum: Always keep your refuse underground. Skulls, bones, hair, etc can be kept indoors without generating miasma. The types that rot can be kept behind a door or, in a pinch, in a room with a diagonal entry. A door is better, though, so you can lock it if you fear necromancers may successfully enter your fortress in stealth. Once you find magma, you can periodically dump the rotting stuff down a hole. Keep the hole covered by a floor grate in between dumpings, or else Magma Crabs may set fire to everything and everyone.