我如何能看到表的结构在SQLite的desc是在Oracle?


您应该能够通过运行来查看模式

.schema <table>

调用数据库文件上的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);

还要注意的是,SQLite将模式和所有关于表的信息保存在数据库本身的一个名为sqlite_master的神奇表中,并且还可以对该表执行普通的SQL查询。例如,上面的文档链接展示了如何使用普通SQL命令派生.schema和.tables命令的行为(请参阅“查询数据库模式”部分)。

. schema的表

哪里的TableName是表的名称

你可以通过输入命令来获得结构:

.schema <tableName>
PRAGMA table_info(table_name);

这对命令行和对连接的数据库执行都适用。

更多细节和示例的链接。谢谢 SQLite编译命令

您可以使用名为SQLite Manager的Firefox插件来清楚地查看数据库的结构。

可以查询sqlite_master

SELECT sql FROM sqlite_master WHERE name='foo';

它将返回一个创建表的SQL语句,例如:

$ 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

如果你正在使用PHP,你可以通过这种方式获得它:

<?php
    $dbname = 'base.db';
    $db = new SQLite3($dbname);
    $sturturequery = $db->query("SELECT sql FROM sqlite_master WHERE name='foo'");

    $table = $sturturequery->fetchArray();
    echo '<pre>' . $table['sql'] . '</pre>';

    $db->close();
?>