java - sync data from file to database -
scenario
i have employee objects in file(flat file), each row representing 1 employee record
i have employee objects in database table employee
i want sync records in file table employee
insert not in table
update there, fields updated
delete records aer not in file, exists in table
one simple solution(not sure, if correct) can think of :
delete records dababase table, , insert reocrds in file table
but want update those, exists already, 1 or more field changed
note: employee_id unique/primary key identify record, , there no duplicate records in file or table
you can create temporary table has same columns employee table. load data file temporary table first, , it’s pure sql operation. example, delete not in file
delete employee employee_id not in (select employee_id employee_tmp);
insert in file not in table
insert employee select * employee_tmp empoyee_id not in (select employee_id employee)
Comments
Post a Comment