How to prevent ?
Prevention they say is better then cure. Use a reputed Virus detection and removal software and remember to update it.
Defragment your Hard Drive as frequently as possible. (best is if you can do it daily).
Use Scandisk to check for logical errors at least once a week and perform a thorough test once a fortnight.
Use a disk mirroring utility. This will help you restore your system in the event of accidental formatting or partition table getting deleted due to some unknown reason.
Create a rescue disk containing the complete CMOS info, MBR info, partition info of all the logical drives as well as Boot record and keep it safely.