Comments - How to create an updater column

 
1 年, 4 ヶ月 ago Daniel Black

Using triggers like:

CREATE TABLE animal (name varchar(30), updater varchar(80));

CREATE TRIGGER update_animal 
BEFORE UPDATE ON animal
FOR EACH ROW SET NEW.updater= current_user;

CREATE TRIGGER add_animal 
BEFORE INSERT ON animal
FOR EACH ROW SET NEW.updater= current_user

 insert into animal (name) values ('dog'),('cat');

select * from animal;
+------+---------------+
| name | updater       |
+------+---------------+
| dog  | dan@localhost |
| cat  | dan@localhost |
+------+---------------+
 
1 年, 4 ヶ月 ago Saki Aoto

Thank you for your comment. As you suggested, I set up a "trigger", but what is added to the updater column is not the username who made the update or insert, but the username who created the trigger.

 
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.