It seems that it is not straightforward for reordering columns
in a sqlite3 table
. At least the sqlite manager
in firefox
does not support this feature. For example, move the column2 to column3 and move column5 to column2. Is there a way to reorder columns in sqlite table, either with a sqlite management software or a script? Thanks.
相关问题
- SQL/SQL-LITE - Counting records after filtering
- What SQLite NuGet package do I need
- How to write the array into the sqlite database fo
- Groupwise MAX() on a subquery
- metaData.getPrimaryKeys() returns a single row whe
This isn't a trivial task in any DBMS. You would almost certainly have to create a new table with the order that you want, and move your data from one table to the order. There is no alter table statement to reorder the columns, so either in sqlite manager or any other place, you will not find a way of doing this in the same table.
If you really want to change the order, you could do:
Assuming you have tableA:
You could create a tableB with the columns sorted the way you want:
Then move the data to tableB from tableA:
Then remove the original tableA and rename tableB to TableA:
sqlfiddle demo
The order in sqlite3 does matter. Conceptually, it shouldn't, but try this experiment to prove that it does:
Populate the table with about 20,000 records where thumbnail is a small jpeg. Then do a couple of queries like this:
Does not matter how many records are returned, on my machine, the first query takes about 0m0.008s and the second query takes 0m0.942s. Massive difference, and the reason is because of the Blob; filesize is before the Blob and basicscanstatus is after.
We've now moved the Blob into it's own table, and our app is happy.
You can always order the columns however you want to in your SELECT statement, like this:
You shouldn't need to "order" them in the table itself.