I am developing a mobile app that will be able to work in offline mode.
I have an online application that consumes a table called "Books" in a database located on a server, and my mobile app has a sqlite database with the exactly table "Books".
When the app gets internet avaible, it syncs the data from "Books" table - located in sqlite - to "Books" table - located in SQL Server.
I am using the MERGE (Transact-SQL) statement to perform it. But I have a problem.
Imagine my mobile app is without internet connection for 7 days and the tables are:
Books(SQL Server)
+----+---------------------------------+--------------+
| Id | Name | LastModified |
+----+---------------------------------+--------------+
| 1 | Modern Operating Systems | 2019-09-20 |
+----+---------------------------------+--------------+
| 2 | The Art of Computer Programming | 2019-09-20 |
+----+---------------------------------+--------------+
Books(sqlite in mobile App)
+----+---------------------------------+--------------+
| Id | Name | LastModified |
+----+---------------------------------+--------------+
| 1 | Modern Operating Systems | 2019-09-20 |
+----+---------------------------------+--------------+
| 2 | The Art of Computer Programming | 2019-09-20 |
+----+---------------------------------+--------------+
| 9 | Computer Networks | 2019-09-26 |
+----+---------------------------------+--------------+
Consider that both tables in sqlite and SQL Server contains Auto Increment Primary Key, if use the "Id" as the criteria of merge, it would get a dirty merge.
How should I do the merge in this case ?