tags:

views:

35

answers:

2

I have a a form on my site that handles employee details.

If there are no associated values in the DB then the form function as a create details form.

If there are associated values in the DB then the form is populated with those values and the form functions as a update/edit form.

Assuming the form is functioning in it's update/edit mode.

Is the best manner to handle the update to delete all the existing values then create new ones?

I am fairly sure it will not matter that the unique ids are being constantly changed.

A: 

I think that is better that you update the values because it's better to preserve the id->employee relation.

mck89
Well the employee id relation would be kept no matter what... DELETE* where employeeid = whatever.. then INSERT empliyeeid = whatever... But I can't do a UPDATE if its new details can I? have to do a insert the first time.. unless I pre-set the values elsewhere..
ian
If there's a new detail it means that the db column that hold that detail is empty but it exists, there's no need to do an insert. You can store the employee id in an hidden field in your form and then you can update the database record with that id with all details submitted by the user.
mck89
Right. But what I am saying is that the column will not always necessarily exist already as the form values are dynamic and it maybe the first time an employees details are edited.
ian
I don't understand. I think that you have a database structure already set so all the columns for details already exist after the creation of the record, if the user doesn't set them they will be empty but they exist so when you update you simply put all form values into the correct column of the table, it's not important if it's the first time that an employee edits his details
mck89
Employees and the Details are separate tables because the details is dynamic.. might be 1 detail might be 30.
ian
aaah now i understand. I think that you should check if the detail already exists and if it not insert it or in this case you can delete all details end re-insert them every time, but i prefer the first choice.
mck89
so check if say.. there are any rows for that employee. if there are zero then insert. otherwise.. delete and insert or whatever... thanks.
ian
A: 

I would think its better to update if it has any type of indexing involved, also you could keep a insert and update timestamps

Phill Pafford