I have my application and I install a .sdf file and I add columns to my database. So how do I update my database without losing my Data?
How To Edit .sdf file
2.4k Views Asked by Zvi W. At
2
There are 2 best solutions below
4

You can execute standard data definition language (DDL) commands in code at application startup.
For example:
myCommand.ExecuteNonQuery("ALTER TABLE MyTable ADD NewColumn1 INT NULL")
We have done this for years in devices ranging from PocketPC to Tablets.
We used to check whether or not a database table or column existed before modifying the DB structure, but we have found it is much easier to record the current database version in a table and then just check the version on startup then make the modifications that we know are necessary between the current version in the database and the application's database version.
You can extend/update a database schema by choosing Default Values for new columns or allow new columns to accept Nulls.