I’m sure sugar is not good for us - but I’ve baked lots of good things and my children have had sugar all of their lives and never had a cavity - ever. They are now 28 and 23 and are consistently told they do a good job of flossing and brushing by their dentists.
No matter what we do, genetics might have something to do with it.
I have a sibling who brushes once in the morning, and that’s it. He doesn’t brush his teeth at night. And he doesn’t floss. He rarely goes to the dentist. He’s in his mid-forties now, and he still hasn’t had a cavity in his entire life. He also never had bad breath. I don’t get it.
He doesn’t eat candy. I’m sure he drinks soda, though. His good teeth must be genetic.
OTOH, I know parents whose young children have gotten cavities simply from eating raisins.