I need a trigger in phpmyadmin for 2 tables.
I have two tables called users
and group_has_users
. Table group_has_users
has 2 values called group_id
and user_id
.
I’m trying to make a trigger that automatically inserts new data to group_has_users
table with user_id
when new user is created in users
table( with group_id
set to 1
)
How to do this with phpmyadmin trigger?
insert into group_has_users (user_id) values (new.user_id);
I have no clue to make it group_id to set 1
.
2
Answers
I think this is what you want:
Note that you will have to run this in your cli or in mysql workbench
Everytime a new record is created in table
users
, you are looking to automatically create a new record ingroup_has_users
, with a defaultgroup_id
of1
.Consider the following trigger:
Demo on DB Fiddle: