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
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.
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 .
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With