Hi all. Quick question about triggers.
Is it possible to set up a trigger such that a specific record in a table NEVER can be deleted?
I'm writing a CMS and I want to set it up such that home pages cannot be deleted.
I guess it would be something like this:
CREATE TRIGGER is_home
BEFORE DELETE ON cms_pages FOR EACH ROW
EXECUTE PROCEDURE check_is_home(...params...);
The function will examine the row being deleted to see if the column is_home is set to 1 (true) or 0 (false) and then act accordingly.
Will doing this actually work? I haven't implemented any triggers on the database yet, I'm just going through everything now and seeing where I can clean up the code and this is one of the most important ones.
Any advice is greatly appreciated.
Thanks in advance,
Pablo
Is it possible to set up a trigger such that a specific record in a table NEVER can be deleted?
I'm writing a CMS and I want to set it up such that home pages cannot be deleted.
I guess it would be something like this:
CREATE TRIGGER is_home
BEFORE DELETE ON cms_pages FOR EACH ROW
EXECUTE PROCEDURE check_is_home(...params...);
The function will examine the row being deleted to see if the column is_home is set to 1 (true) or 0 (false) and then act accordingly.
Will doing this actually work? I haven't implemented any triggers on the database yet, I'm just going through everything now and seeing where I can clean up the code and this is one of the most important ones.
Any advice is greatly appreciated.
Thanks in advance,
Pablo