I have a small C# Windows Forms application. It uses SQLite DB on the client's PC. I started with a Schema DB and with time I added more tables and columns to my local DB (not the client's).
I want to upgrade the client's DB Schema without losing data. So far I could update the schema but some information is lost because of drop tables and recreating them.
Can anyone help me?
This is an example of 2 tables. I just add new columns. No easy diagram generator for SQLite. Add **** for added columns
Table Usuarios CLIENT
UserId Integer
NombreUsuario TEXT
Password TEXT
ProfesionID Integer
Mail TEXT
Table Usuarios NEW VERSION
UserId Integer
NombreUsuario TEXT
Password TEXT
ProfesionID Integer
Mail TEXT
UseImages Integer ****
Color Integer ****
BackUpDate TEXT ****
Table EquiposHabilitados CLIENT
EquipoID TEXT
Table EquiposHabilitados NEW VERSION
Equipo TEXT ****
EquipoID TEXT
EquipoFechaVencimiento TEXT ****
UltimoTiempo TEXT ****
1 Answer 1
I'd alter existing tables when adding new columns but I read there are some concerns to considerate when altering tables, check https://www.sqlite.org/lang_altertable.html
Focus in the 7. Making Other Kinds Of Table Schema Changes
section, in the square of correct and incorrect steps to drop/re-create a table
EquiposHabilitados
table, you changed the column order by adding the new columnEquipo
before theEquipoID
. Is it acceptable for you to design it instead to addEquipo
afterEquipoID
?...This would simplify the solution, and generally you shouldn't care about column order in Tables too much.