(a) Whenever a judgment is obtained by a creditor on a demand to which there are one or more sureties, the sureties may pay such demand, and the same shall be transferred by operation of law to the surety or sureties paying or satisfying such demand, who shall have all the liens or equities of such judgment and of the debt or claim on which the same is founded.
(b) The plaintiff in the judgment, his agent or attorney of record, when the payment is made, must assign such judgment to the surety or sureties paying the money, who may collect the same, with interest and costs, in the name of the plaintiff for their use, and may assert any lien or right against the principal debtor which the plaintiff could have asserted if the debt had not been paid.