mysql - my trigger inserts way to many records -


i have following trigger:

    begin  insert user_has_competence (user_id,competence_id)  select u.id,c.id competence c  join user u on u.organization_id = c.organization_id , c.organization_id = new.organization_id; end 

the tables involved following:

    table: competence columns: id  int(11) ai pk name    varchar(400) organization_id int(11) competence_type_id  int(11) competence_category_id  int(11)   table: user columns: id  int(11) ai pk username    varchar(100) password    varchar(100) is_active   int(11) user_type_id    int(11) token   varchar(445) organization_id int(11) title_id    int(11) image_path  varchar(100) division_id int(11)      table: user_has_competence columns: user_id int(11) pk competence_id   int(11) pk competence_level_id int(11) progression varchar(45) id  int(11) ai pk 

now have 8 users , when insert 64 competence end inserting on 30k rows user_has_competence

can tell me why happening??

to more precis inserts 626433 rows.

looks user can have 1 competence per organisation? if so, i'd suggest having composite pk on user_id, competence_id, organisation_id in user_has_competence table. ( need add organisation_id there). then, you'll see errors when trigger try insert duplicate values

edit: part of problem may trigger not include clause new competence_id inserted, add duplicates existing user-competence relationships


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -