Approach uses ALTER TABLE to add columns when backup and RESTORE a database file in android. How to set new columns position in table. The columns is showing as a last columns in table but i need this column in middle.
Asked
Active
Viewed 166 times
-1
-
1Why do you want your column in the middle? Just order the fields whenever you make a query. Or is there any other meaning for that feature? – reixa Jun 05 '15 at 11:28
-
No, my client define the table structure so can't change the order. – Ritesh Jain Jun 08 '15 at 05:11
-
Can we use alter table and add new column in middle? – Ritesh Jain Jun 08 '15 at 05:12
-
If you have a new question, please post it as a new question and don't vandalize your old questions. – laalto Nov 27 '15 at 10:47
2 Answers
1
You can try different approaches to maintain the positioning of columns.
One way can be to 1) rename your table 2) create new table with correct column ordering 3) then insert all records from renamed table. This is mentioned on following link: https://stackoverflow.com/a/4253879/867475
Another approach can be to add the column at the end and use Views to fetch columns in correct ordering. Example.
0
As per documentation
The
ADD COLUMN
syntax is used to add a new column to an existing table. The new column is always appended to the end of the list of existing columns.
But, there is a work around way. Read this answer on SO.
Refer to: SQLite: ALTER TABLE: ADD COLUMN