- Home /
Answer by ArkaneX · Sep 09, 2013 at 09:03 PM
From question tags I assume you're talking about sqlite, though it doesn't really matter. It's hard for me to think of a real world scenario, where delete+insert would outperform update in relational database. Each of these commands is there for a reason, and is optimized for a specific task.
Do you have some real problem with performance of your database operations? Or is this a general question? In first case, please describe your issue. In the second, please assume update is faster.
"There's more than one way to do it or T$$anonymous$$TOWTDI" to get the same result, That is always has been my case with coding. some people think that using update will be slower and others say its delete and insert, when replacing something on a table i preferred update because codes will be shorter and more readable in unityscript, i'm not sure about delete and insert though.
I agree that you can use both, but you should stick with update. Apart from code being shorter and more readable, it will be faster. To convince you, I suggest to execute some tests.
Create a table in the db, with columns that you require. Insert as many rows, as you predict your table will contain. Create proper indexes, and then run update of random data in a loop. Repeat this for delete/insert, and compare results. I bet update wins :)
As to the loop count, I suggest starting from 1000. See what is the execution time, and tune the count to make execution last at least 10-20 seconds (for update). And then use the same count for delete/insert.
Also - remember to execute both scenarios a few times, and discard worst and best cases from each.
Your answer
Follow this Question
Related Questions
Implementing an offline Inventory that must sync with a server 0 Answers
VR Highscore with database (SQLite) 1 Answer
Hiding the SQLite file 0 Answers
Can't Connect to SQLite after Build..... 3 Answers
how make player database 1 Answer