Ano*_*eek 371
PRAGMA table_info(table_name);
Run Code Online (Sandbox Code Playgroud)
这将适用于:命令行和针对连接的数据库执行时.
链接了解更多详情和示例.谢谢 SQLite Pragma Command
met*_*att 316
sqlite3在数据库文件上调用该实用程序,并使用其特殊的点命令:
.tables 将列出表格.schema [tablename] 将显示一个或多个表的CREATE语句还有许多其他有用的内置点命令 - 请参阅http://www.sqlite.org/sqlite.html上的文档,sqlite3的特殊命令部分.
例:
sqlite> entropy:~/Library/Mail>sqlite3 Envelope\ Index
SQLite version 3.6.12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
addresses ews_folders subjects
alarms feeds threads
associations mailboxes todo_notes
attachments messages todos
calendars properties todos_deleted_log
events recipients todos_server_snapshot
sqlite> .schema alarms
CREATE TABLE alarms (ROWID INTEGER PRIMARY KEY AUTOINCREMENT, alarm_id,
todo INTEGER, flags INTEGER, offset_days INTEGER,
reminder_date INTEGER, time INTEGER, argument,
unrecognized_data BLOB);
CREATE INDEX alarm_id_index ON alarms(alarm_id);
CREATE INDEX alarm_todo_index ON alarms(todo);
Run Code Online (Sandbox Code Playgroud)
另请注意,SQLite在名为sqlite_master的魔术表中保存模式以及有关数据库本身中表的所有信息,并且还可以对该表执行常规SQL查询.例如,上面的文档链接显示了如何使用常规SQL命令派生.schema和.tables命令的行为(请参阅:查询数据库模式一节).
Mic*_*ann 38
你可以查询 sqlite_master
SELECT sql FROM sqlite_master WHERE name='foo';
Run Code Online (Sandbox Code Playgroud)
这将返回一个create tableSQL语句,例如:
$ sqlite3 mydb.sqlite
sqlite> create table foo (id int primary key, name varchar(10));
sqlite> select sql from sqlite_master where name='foo';
CREATE TABLE foo (id int primary key, name varchar(10))
sqlite> .schema foo
CREATE TABLE foo (id int primary key, name varchar(10));
sqlite> pragma table_info(foo)
0|id|int|0||1
1|name|varchar(10)|0||0
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
269710 次 |
| 最近记录: |