Lets say I have 2 database files, main and new database. Everytimes when new database file is released, Users need to update main database from new database.
- If certain row is found e.g. CustomerName is same, then I need to update old records in main database.
- If it is not found, then I need to insert new record into main database.
What I had tried is select all rows from new database, then go through row by row by using reader.Read(). Inside the loop I will check if update sql return -1, then I will execute the insert sql.
The above approach was having performance issue, as it need to go through every rows to execute update or insert. My proposed solution is to attach new database into main database, then carry out "INSERT or REPLACE table SELECT * FROM newdatabase.table".
But soon I realized a problem. I do not actually have a primary key in table, or the primary key does not help to decide INSERT or REPLACE. This is due to some specific customer requirement. In this case, I cannot use INSERT or REPLACE without primary key e.g. column to compare (CustomerName) is not unique or primary key.
Please let me know if you have any better solution, thank!