You’re going to have to set him up to fail, and make it a self-correcting exercise.
You say he’s a rescue pup, so I’m going to assume you haven’t had him long. Work on some positive reinforcement obedience and tethering him to you (also known as “umbilical cording” google it) and limit his access. The more time you spend with him, the more he will bond to you and see you as the reward, instead of the table.
He’s a little guy, so feeding him several times a day might help as well. Also, get some food based toys. Stuff a Kong with wet food and freeze it, that’s always fun. And Buster food cubes are great, one of the all-time best dog toys.
Do all that and put something unpleasant up on the table. A scat mat, a carpet runner, nubby side up, upside down mousetraps work GREAT, they make a big noise and fly up into the air. Do your best to keep temptation off it, so that he never finds a reward up there, just various not-fun things and let him self-train.
We’re also going to cure counter-surfing. Get a few soda cans with the tab attached. Put 4-5 pennies in each, then tape over the opening. Put a string through the tab and tie 2-3 together, then, with a longer string, tie them to something wonderful, like a chicken leg. Leave it peeking over the edge of the counter or table. When Pup pulls it down, he also pulls down Thunder Itself right onto his face. When you hear the clamor, dash to him and scold - and rescue if needed, I once had a pup reflexively clamp down on the bait when he ran, dragging the cans after him - to his horror! He was too startled to open his jaws, but never stole food off the counter again.
And no, this does not give a pup a fear of loud noises, gunshots or thunder. I’ve done this with a LOT of pups and never had an issue (owners always think it will). Shaking that can will set them walking the straight and narrow even years later though 