当我在sqlite文件中查看我的大表时,使用sqlite浏览器,如Firefox插件SQLite Manager或SQLite Browser,我看到列是根据它们的添加顺序显示的表(我一直在循环中添加新列)。
A J D B
--- --- --- ---
.. .. .. ..
这是一种视觉上的烦恼,因为表非常大,有很多列,为了调试,我需要目视检查相邻的列。如何对表进行排序以便对列进行排序,如:
A B J D
--- --- --- ---
.. .. .. ..
感谢。
答案 0 :(得分:1)
SQLite没有内置机制来重新排序表的列。
您必须重新创建表格:
CREATE TABLE new_MyTable(A, B, J, D [...]);
INSERT INTO new_MyTable SELECT A, B, J, D FROM MyTable;
DROP TABLE MyTable;
ALTER TABLE new_MyTable RENAME TO MyTable;
答案 1 :(得分:1)
您可以创建 DebugView ,并根据需要重新排序列...
CREATE TABLE ChorleyHandford (IMAGE_REF, DATE, LOCATION, NUMBER);
INSERT INTO "ChorleyHandford" VALUES('A10006','16/10/1990','RATCLIFFE POWER STATION CASTLE DONNINGTON POWER STATION','27');
INSERT INTO "ChorleyHandford" VALUES('A10017','25/10/1990','BROMLEY PARKS','17');
INSERT INTO "ChorleyHandford" VALUES('A10018','25/10/1990','CROSSWAYS BUSINESS PARK DARTFORD CROSSING BRIDGE CONSTRUCTION','20');
INSERT INTO "ChorleyHandford" VALUES('A10022','25/10/1990','THURROCK LAKESIDE','11');
INSERT INTO "ChorleyHandford" VALUES('A10057','01/11/1990','CLANDON REGIS SITE','6');
看看你有什么:
select * from CHORLEYHANDFORD;
A10006|16/10/1990|RATCLIFFE POWER STATION CASTLE DONNINGTON POWER STATION|27
A10017|25/10/1990|BROMLEY PARKS|17
A10018|25/10/1990|CROSSWAYS BUSINESS PARK DARTFORD CROSSING BRIDGE CONSTRUCTION|20
A10022|25/10/1990|THURROCK LAKESIDE|11
A10057|01/11/1990|CLANDON REGIS SITE|6
创建一个重新排序的视图,看看它现在的样子:
create view dbgview as select NUMBER, LOCATION, DATE, IMAGE_REF FROM CHORLEYHANDFORD;
select * from dbgview;
27|RATCLIFFE POWER STATION CASTLE DONNINGTON POWER STATION|16/10/1990|A10006
17|BROMLEY PARKS|25/10/1990|A10017
20|CROSSWAYS BUSINESS PARK DARTFORD CROSSING BRIDGE CONSTRUCTION|25/10/1990|A10018
11|THURROCK LAKESIDE|25/10/1990|A10022
6|CLANDON REGIS SITE|01/11/1990|A10057