General tidy up of all SQL code.

When saving edits made to a link, check to see if any tags have been
removed, and if so check to see if they still apply to any other links.
If they don't, delete them.
Initial search implementation.