The process differs by device so you need to read and research what's involved for your phone. Generally (at least for most devices I have had) it tends to involve unlocking a phone's bootloader as part of the process, which will wipe the internal storage as a built-in security measure.
It's sensible to have some sort of regular backup regime anyway, say by full cloud backup or copy internal SD card contents to PC every so often, since for example taking OTAs can be a risk if the update process fails part way through. Some phones suffer from "sudden death syndrom", get lost/stolen and so on, so I wouldn't consider everything on your sd card safe anyway - regardless of whether you are considering rooting or not.