SQLite Reorder Table?
C开发者_JAVA技巧an you reorder SQLite table columns via a query?
I would prefer a query method, but if that is not possible is there any other way?
Yes, you control the order of columns by the order you name them in the query. Both these queries return the same rows, but the columns are in a different order.
select first_column_name, second_column_name
from mytable;
select second_column_name, first_column_name
from mytable;
If you want it to appear that the columns in the base table have been permanently changed, you can use a view.
create view mytable_reordered
select second_column_name, first_column_name
from mytable;
If you wanted to make that change transparent to application programs, you'd first rename the table, then create the view, giving it the old name of the table. Finally, you'd jump through whatever hoops your dbms requires in order to make that view updatable. In SQLite, I think that means writing code to implement some INSTEAD OF
triggers.
精彩评论