So I have a question regarding the best practice for a PHP page inserting a new row into a table. There are some required fields (aka NOT NULL) and some optional fields (can be NULL). Is it better to insert everything with one query, or just do the required fields, get the inserted ID and update the other fields with one or more other queries?
Is there a big performance hit if I do multiple updates with a where <primary key> = "x"? Or is it better to do multiple updates so that if one of the optional updates doesn’t work, the rest do?
In general you should do a single INSERT with all the values. This will be less expensive in terms of database processing but equally importantly (or moreso) it will make your application code much simpler.
I’m not sure why the alternative even occurred to you, but it makes me think that perhaps there’s some application specific reason you feel some of the subsidiary column values will be rejected. If that’s so, please tell use more about your specific situation.