Sugar is the main cause of dental decay when there is bacteria present. More important than the amount of sugar you take is the frequency of it.
Probably the worst thing you can do to your teeth is to hold a soda and have a sip every few minutes during a long period of time; the same is true for snacking. It is recommended that if you want to have a snack or a soda or juice it is better to have it after food, as dessert or have it in one sitting. Eating or drinking something sweet during a long period of time creates a constant supply of sugar for bacteria that cause tooth decay!
It is important to know all the sources of sugar. It is not just everything that is sweet but anything that can turn to sugar like pieces of bread. Cutting down your sugar intake is good for cavity prevention as well as general health.
When you have to have sugar, the best way to prevent cavities is to prevent the sugar from staying next to your teeth. Brushing after eating sugar, rinsing your mouth with Fluoride mouth wash or chewing sugarless gum can help. But nothing has the effect of avoiding sugar!
Is there any kind of food that prevents tooth decay? Well, not really. Some people believed that chewing foods like apple and carrots may have some plaque removal effect, but they still contain some sugar so any advantage of them is not clear.
Another group of food that causes significant damage to teeth structure is acidic foods. Things like lime, lemon and grapefruit, if in frequent contact with teeth, can cause serious irreversible damage (erosion) to your teeth.