Is there a function to automatically update a column specifying who created a new record in a sql table?
Something similar to the timestamp, but that instead of the time it shows the user who has added the record.
e.g.
value user 111 Luis 111 Admin 112 Luis
Advertisement
Answer
with MySQL itself you cannot do it. The only user known by MySql is the current_user()
which the application uses to connect.
you can create Trigger in order to save this user but I believe this does not worth much
created_by varchar(100); create trigger table_insert_trig before insert on table for each row begin set new.created_by := current_user(); end;
Another option is to pass current_user from your application using your Data Access Layer, but this is unrelated with MySql itself and it is Application Logic.