Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite Add Column into table at a certain position (Android)

This is the code that works for adding a column.

mDb.execSQL("ALTER TABLE " + table_name + 
            " ADD COLUMN " + column_name + " text");

My problem the column is created at the last position of the table.

Column1|Column2|Column3|Column4|Column5|NewAddedColumn6

E.g. Is is possible to add a column between Column3 and Column4???

Column1|Column2|Column3|NewAddedColumn6|Column4|Column5
like image 567
Tower Jimmy Avatar asked Mar 31 '14 00:03

Tower Jimmy


People also ask

How do I add a column to a specific position?

To add a column at a specific position within a table row, use FIRST or AFTER col_name . The default is to add the column last. You can also use FIRST and AFTER in CHANGE or MODIFY operations to reorder columns within a table.

Can we specify the position where a new column has to be added?

Answer. Yes, you can add a new column in a specified position into a dataframe, by specifying an index and using the insert() function. By default, adding a column will always add it as the last column of a dataframe. This will insert the column at index 2, and fill it with the data provided by data .

How do I add a column to a table in SQLite?

Use ALTER TABLE table_name ADD COLUMN column_definition statement to add a column to a table. Use ALTER TABLE table_name RENAME COLUMN current_name TO new_name to rename a column.

Can we specify position of the column in SQL?

How do I change the position of a column in a table in SQL? In Object Explorer, right-click the table with columns you want to reorder and select Design. Select the box to the left of the column name that you want to reorder. Drag the column to another location within the table.


1 Answers

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.

Hence, answer to your question is NO

But, there is a work around way.
Read this answer on SO.

Refer to: SQLite: ALTER TABLE: ADD COLUMN

like image 70
Ravinder Reddy Avatar answered Oct 03 '22 21:10

Ravinder Reddy