Changing a car battery without losing the codes

A 9V battery would not supply enough power to have the key in the accessory position. You would need one of those 12V jump start devices in that case.