I have a basic CRUD application where people are adding records. When they INSERT
someone new, there are many updates (about 100) that need to be done to the record after it's been added.
I have tried to put the UPDATE
statements in a TRIGGER
but it would either lock the table --OR-- give me the "can't update table in stored function/trigger because it is already used by statement which invoked this stored function/trigger" error.
Then I tried to put them all in a PROCEDURE
-- which took about 30 seconds to run. Unacceptable.
I don't think I'm doing anything difficult here. Mostly, the updates are updating one field based on another.
Example
INSERT INTO data_table (field1, field2, ...) VALUES ('$field1', '$field2', ...);
Then the updates:
UPDATE data_table SET field2 = 'New York City' WHERE field1 = '212';
UPDATE data_table SET field2 = 'Los Angeles' WHERE field1 = '213';
etc.
Would it be faster/more efficient to do a bunch of IF...THEN
statements in PHP to change the variable before inserting?
I'm just trying to speed up the process of inserting the record and processing the updates. Any help?