javaandroidsqlsqlitesqlhelper

Java/Android SQL Helper Class Why drop the table when upgrading?


For the majority of the examples and tutorials I have seen it is always suggesting to execute SQL to Delete the table if it exists in the onUpgrade method.

Why would you want to delete the table as this would remove all the data, would it not be better to just replace the old DB version with the new version?

This would something that I could not understand and no where online outlined the reason.

Thanks

| Sam |


Solution

  • Because they are tutorials: they assume you have no valuable data in them (or no data at all). In that case, the easiest way to upgrade a schema is to remove old tables and creating the new ones.

    Don't take in mind it, you are right.