mysql - Computed field value based on other column while insertion -
i have table have id
column(primary key auto increment) , 1 more column name.
i want fill name column's value automatically while insertion based on generated id column value in format
<idcolumnvalue>_school
i aware of 2 ways this
- using trigger
- inserting row first , update column value based on inserted row id column value
but want make field non nullable use second option have make nullable.
is there direct way while inserting row can have field non nullable?
as said in comment, can use temporary value name
column. can use request :
insert `table` values('', 'name') /*let's assume name real name want insert*/
i'm not sure how use trigger, may want write :
delimiter # create trigger update_name_after_insert insert on `table` each row begin update `table` set name = concat_ws("_", id, name) end#
Comments
Post a Comment