Movies and pop culture all have swords being handed down through generations, but I'd have thought the constant dents and sharpening required would eventually scrape away enough steel that you'd need to replace it eventually.
How long would a well made sword from, the Gaelic Wars, the 5th century, 1066 and, say, a cavalry sabre from the Napoleonic wars last?
My knowledge of the lifespan of iron and steel in incomplete. That said, both are essentially imperishable given proper care and upkeep. If nothing especially disastrous happened to a sword, it could be expected to last very many human lifespans when attended to properly.
Correct attention varies, but it essentially boils down to keeping a sword oiled to prevent atmospheric moisture from rusting the blade. Additionally, the sheath or scabbard will gain its own internal lining of oils when housing an oiled sword regularly, reducing the required frequency of sword oiling. I don't have the source at hand, but I believe there was a sword recovered from an imperial Chinese tomb that had a scabbard so finely fitting its sword's blade that it completely sealed the sword and oil from general atmospheric conditions, preserving the blade to the current day.
Of course, all that ignores the rough-and-tough of actual combat application, and the upkeep that ensues from that. The first thing to note, of course, is that a sword can outright break or bend out of functional shape. The former is more common of steel swords (having harder exteriors) and the latter of swords made of iron or bronze (being more malleable). Assuming neither of these things happen, though, there are all the scratches, dents, and notches you point out.
Now, one thing that needs to be said here is that historical fiction, fantasy fiction, and real history often mingle in pop-cultural consciousness, which results in a perspective that assumes historical people were living sword fight to sword fight. Naturally, this isn't the case, and wearing a sword in civilian life was probably more useful socially than martially on most regular days. Even in battle, the sword was a "primary" weapon for relatively few combatants throughout history, at least compared to the martial ubiquity Western pop culture attributes to the sword.
Now, on top of all that, there's quite a diversity of ways to use a sword when it comes time to cut a knave. The way the sword is used will influence the kind of damage it takes, on top of its materials, construction, and its state of durability when used. For instance, some historical and modern fencers advocate the "edge parry", which is kind of a disingenuous term, as the edge parry is really an attack that doubles as a parry. The general idea is to ensure that the path of your attack crosses the path of theirs, creating a situation when you intercept their attack while continuing to display threats. This kind of parry is not overwhelmingly damaging to a sword, but definitely risks notches.
Contrary to the edge parry is the "flat parry". Unlike the edge parry, the flat parry is actually, primarily a defense. The idea is to take an opponent's blow on the flat of the blade, allow it to slide off, and to use the impact on your weapon as a source of physical motivation by which to return the attack. The flat parry does cause less damage to the sword, but the flat is moderately likely to sustain scratches and dents anyway.
So, with all this taken into consideration, plus additional upkeep like sharpening, how long is a sword likely to last? Ultimately, I have no idea. But these are some of the factors you can look at when seeking additional information. Keep in mind that, while historical people often lived in more dangerous conditions than a modern, first-world Western person, violence was still something many people avoided where possible. Having a sword was no guarantee of using it, or wanting to use it. A sword passed down the generations might see several generations of disuse, or it might not. Additionally, such a sword is likely to have whole components replaced, up to and including the blade.
At least in some cases, then, it might be a matter of what you consider the "same" sword. If a sword's blade is replaced by another blade of identical design and construction, is it the same sword? What about the hand guard, pommel, or grip? Those kinds of questions fall more into philosophy than strict history, but different historical people might have different opinions concerning that question. It's also likely that at least some surviving swords passed down generations have undergone component replacements during their lifetimes. This question threatens to be much more abstract than most would immediately anticipate.
There is a tremendous variety in swords, but in many cases, damage to a sword could be repaired by welding fresh steel to the blade edge, regrinding and redoing the heat treatment. With this taken into account, it can be like the classic bit about grandpa's axe "It's had the handle replaced 9 times and the axe head replaced 3 times, and it still works as good as the day he bought it".
Exactly when it would be considered appropriate to replace a sword instead of repair it would be dependent on the means of the owner. In many cases, a warrior wielding a sword would be a noble, who could afford to replace his sword regularly if needed, or a mercenary who would treat a sword as a rather important business expense. For many battles, conscripts; the lowly peasants being made to fight would be armed with alternative weapons: pikes, or whatever nasty tool they could salvage from the farm, such as a bill-hook.