1

Can I have a trigger to check any insert or update on whole database?

I tried this but it didn't work:

create trigger updateHistory after insert on database

Furuchi
  • 35
  • 3
  • "Can I have a trigger to check any insert or update on whole database' - no you cannot, triggers are on a per table basis. – P.Salmon Jul 20 '19 at 08:16

1 Answers1

0

Yaou need to elaborate the database into separate tables. And give the action. Eg:


CREATE TRIGGER updatehistory
    BEFORE UPDATE ON `table,table2`
    FOR EACH ROW 
BEGIN
    INSERT INTO 
    SET action = 'insert',
     record = OLD.record,
        changedat = NOW(); 
END

And as answered here, you cannot create both insert and update at the same trigger, but you can move the common code into a procedure and have them both call the procedure.

Jastria Rahmat
  • 776
  • 1
  • 6
  • 27