I'm a long time php/mysql developer however have only recently started looking into using triggers. From my understanding, you can use them to perform actions when a record is added/modified/deleted.
With this in mind, I had a thought about a current simple cms script I'm putting together. As it stands I've been planning on having it so that a URL slug is created based on the page name (e.g a page titled 'Hello World' would have the slug 'hello-world').
Generally when I've done this before, I've checked to see if the slug is already in use, and thrown back an error to the user asking them to modify it, or in somecases where the slug isnt too important, appended '-1' to the end of it, or '-2', '-3', etc if the number was already in use.
However with triggers, its given me a possible idea, however I have a feeling it may be 'out of scope' for what triggers can/should be used for.
My thinking was that as a record is inserted, it runs a query to check and see if the slug is already in use, then if it is, changes it. The only problem I cant work out how to solve (if it is indeed even possible) is to keep iterating through records until it finds a free one (e.g so if 'hello-world', 'hello-world-1' and 'hello-world-2' were taken, it'd essentially loop through all three, then finally arrive at 'hello-world-3' as the slug that's free to use.
Is this worth pursuing or am I overcomplicating things here for the sake of trying to use a trigger?