I would like to have my service panel upgraded from 50 to 200 amps by licensed electrician, but am worried about preexisting code violations. If I had it upgraded and a building code inspector came out to inspect it, would he/she just inspect the new panel work or do they check the whole house for all building code violations?
Under the NEC, electricians are held to a very high standard when upgrading systems in existing homes. In many areas, the last electrician to have worked on a system can be held responsible for the whole system. For this reason, most electricians will be very careful to check for any visible or obvious problems and insist they be corrected before new work is done. As for building inspectors, they come in all degrees of harshness. Older style electrical work that does not meet current codes, but was and still is safely operational is most always grandfathered and the code enforcement inspector cannot force you to upgrade them unless it effects the new work or presents an imminent hazard. However, if you have substandard or unsafe conditions, any good electrician or inspector are going to point it out and insist on repairing it properly. This is to fulfill their obligation to assure your safety.
In most jurisdictions, a renovation to an existing building that requires a permit will require that the existing building's subsystems be brought up to current minimum code, to the extent that the renovation relies on that subsystem. For electrical, that means that any wires that are ties into by the electrician must be up to code along the entire circuit all the way back to the panel. If the panel itself doesn't meet code, that must be replaced as well, and in some cases even the wiring out to the pole is the responsibility of the homeowner and thus the electrician doing the work. Plumbing is a little less strict, but many plumbers who find old pipe or code violations will take out as much as is feasible, so they have no worries about what they're tying into. Gas guys, same thing.
Let's say your house is really old, and has some knob & tube wiring. Perfectly safe behind sealed interior walls UNTIL you try to load that circuit beyond 10 amps; then the knobs (which insulate joins and corners of wire runs) heat up, arc, and start fires. Now, the standard is insulated multi-conductor cable, with all wire joins located in fire-rated, accessible junction boxes. It is illegal, ANYWHERE, to simply wire-nut some modern 3-conductor insulated wire to the end of a knob & tube conduit and start using that; the entire run, all the way back to the panel, must be ripped out and replaced with modern 2- or 3-conductor wire in the proper gauge for the required load. Usually, when an electrician catches any hint of knob & tube in a house, he will insist that the entire house's wiring be brought up to code even if he isn't touching any knob & tube himself, because if he knows about it, doesn't do anything about it, and the house burns down, he can be held liable, lose his license and even go to jail even if it wasn't his work that failed.