Im trying to make a trigger in mySQL that will update a colum with data from another table, when i do a insert.
I got table: rtsEP_groups
With: id, name
and table: rtsEP_users
with: id, groups (and alot of others)
And i want to update “groups” in rtsEP_users, with the “id” from rtsEP_groups where “name” is “Student”, when there is a new insert in rtsEP_users.
I was working on this trigger, but not sure if its right, and how to finish it.
How to update the right colum.
CREATE TRIGGER defaultGroup
AFTER INSERT ON rtsEP_users
BEGIN
DECLARE _group_id INTEGER;
SELECT id INTO _group_id FROM rtsEP_groups WHERE name = "Student"
UPDATE rtsEP_users SET groups = _group_id WHERE
Use
BEFORE INSERTinstead ofAFTER, soNewis represent of inserted row that you can update.Try this