sqlite3提供了多个命令来查看数据库的schema".tables"命令可以查看当前数据库所有的表
示例14:
java代码:
sqlite> .tables
tbl1
tbl2
sqlite>
".tables"和在list模式下执行下面的语句相似:
SELECT name FROM sqlite_master WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%' UNION ALL SELECT name FROM sqlite_temp_master WHERE type IN ('table','view') ORDER BY 1
实际上, 如果你查看sqlite3程序的源码 (found in the source tree in the file src/shell.c), you'll find exactly the above query.
另外,".tables"命令后也可以跟一参数,它是一个pattern,这样命令就只列出表名和该参数匹配的表。
示例14-1:
java代码:
sqlite> .tables
.tables
android_metadata bookmarks system
bluetooth_devices secure
sqlite> .tables s%
.tables s%
secure sqlite_sequence system
sqlite>
".indices"命令列出指定表的所有indices(索引)。第一个参数为表的名字。
示例15:
java代码:
sqlite> .schemasystem
.schemasystem
CREATETABLEsystem (_idINTEGERPRIMARYKEYAUTOINCREMENT,nameTEXTUNIQUEONC
ONFLICT REPLACE,value TEXT);
CREATEINDEXsystemIndex1ONsystem (name);
sqlite> .tables
.tables
android_metadata bookmarks system
bluetooth_devices secure
sqlite> .indices system
.indices system
sqlite_autoindex_system_1
systemIndex1
sqlite>
".schema"命令,在没有参数的情况,它会显示最初用于创建数据库的CREATE TABLE和CREATE INDEX的SQL语句。比如,示例16
".schema"命令可以包含一个参数,它是一个pattern,用于对表进行过滤,这时只会显示满足条件的表和所有索引的SQL语句。
比如,示例15和示例17.
示例16:
java代码:
sqlite> .schema
.schema
CREATETABLEandroid_metadata (locale TEXT);
CREATETABLEbluetooth_devices (_idINTEGERPRIMARYKEY,nameTEXT,addr TEXT,chan
nel INTEGER,typeINTEGER);
CREATETABLEbookmarks (_idINTEGERPRIMARYKEY,title TEXT,folder TEXT,intent TE
XT,shortcut INTEGER,orderingINTEGER);
CREATETABLEsecure (_idINTEGERPRIMARYKEYAUTOINCREMENT,nameTEXTUNIQUEONC
ONFLICT REPLACE,value TEXT);
CREATETABLEsystem (_idINTEGERPRIMARYKEYAUTOINCREMENT,nameTEXTUNIQUEONC
ONFLICT REPLACE,value TEXT);
CREATEINDEXbookmarksIndex1ONbookmarks (folder);
CREATEINDEXbookmarksIndex2ONbookmarks (shortcut);
CREATEINDEXsecureIndex1ONsecure (name);
CREATEINDEXsystemIndex1ONsystem (name);
sqlite>
示例17:
java代码:
sqlite> .schemas%
.schemas%
CREATETABLEsecure (_idINTEGERPRIMARYKEYAUTOINCREMENT,nameTEXTUNIQUEONC
ONFLICT REPLACE,value TEXT);
CREATETABLEsqlite_sequence(name,seq);
CREATETABLEsystem (_idINTEGERPRIMARYKEYAUTOINCREMENT,nameTEXTUNIQUEONC
ONFLICT REPLACE,value TEXT);
CREATEINDEXsecureIndex1ONsecure (name);
CREATEINDEXsystemIndex1ONsystem (name);
sqlite>
【责任编辑:立方 TEL:(010)68476606】
内容导航