The only dwarves I've ever noticed using a table for eating are those who own the room the table is in (e.g. book keeper, mayor, nobles etc). A dwarf who owns a table will prefer that table over any others hence why you'll see your book keeper eating at his office desk.
If you have a constructed table which isn't part of a room, the dwarves will consider that a "free" table. They should prefer tables in dining rooms though over "free" tables but if the "free" table is closer to them when they decide they need to eat, they will pick that table to eat at instead. Note I said when they need to eat, not when they pick up food so building your dining room next to your food stockpile won't make any difference if they're 200 steps away from the dining room but 10 steps away from a "free" table as they'll run all the way over to your food stockpile & then back again to the "free" table as decisions about where to eat once they've got their food are made as soon as they get the "Eat" job.
noob if you want to stop people sleeping in hospitals, give them their own beds. Either build every dwarf his or her own bedroom & make sure they're assigned at least one room (married couples will share a bedroom but you can assign them both separate rooms if you like) or build dormitories with enough spare beds to house everyone who needs to sleep at any given time. Note dormitories, like most things in this game, are bugged & you need to create a dormitory from each bed in the room otherwise they'll only see the bed you used to create the dormitory as being part of the dormitory (the rest will be seen as "free" beds same as the ones in the hospital are so again like the table issue above if they're closer to the hospital than the dormitory, they'll sleep in the hospital).