MySQL How to automatically insert different values into a table -
let me describe problem. let´s have attribute_id´s id (82, 93, 284, 343, 432, 537). table has columns (id, rule_id, attribute_id, _position, required)
now, want insert few more rows got specifics: -id change automatically - no issue -rule_id same, defined variable - no issue -attribute_id change, (82, 93, 432 - 3 rows) or (343, 284, 537, 82, 93 - 5 rows) - here main problem -_position start 1 , end 1 + number of rows. - no issue -required value 0. -no issue
i dont want write:
insert ind_rule_attribute (rule_id, attribute_id, _position, required) values (rule_id_"var", 82, 1, 0); insert ind_rule_attribute (rule_id, attribute_id, _position, required) values (rule_id_"var", 93, 2, 0); insert ind_rule_attribute (rule_id, attribute_id, _position, required) values (rule_id_"var", 432, 3, 0);
rather use somehow loop fill let´s 82, 93, 432 - variable - code work me. first question here sorry if made mistakes in description couldn't find answer here or searching on google.
you can use preparedstatement if using jdbc or native query using jpa insert ind_rule_attribute (rule_id, attribute_id, _position, required) values (rule_id_"var", ?1, ?2, ?3);
then set prepstatment.setparameter(1, value1); set prepstatment.setparameter(2, value2); set prepstatment.setparameter(3, value3);
if inserting values directly db using mysql client utility, need write storedprocedure in setting values in variables.
Comments
Post a Comment