本文介绍了如何在 SQLite 中查看表的结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 SQLite 中的表结构视为 desc 在甲骨文?

How can I see the structure of table in SQLite as desc was in Oracle?

推荐答案

调用数据库文件上的 sqlite3 实用程序,并使用其特殊的点命令:

Invoke the sqlite3 utility on the database file, and use its special dot commands:

  • .tables 将列出表格
  • .schema [tablename] 将显示一个或多个表的 CREATE 语句
  • .tables will list tables
  • .schema [tablename] will show the CREATE statement(s) for a table or tables

还有许多其他有用的内置点命令——请参阅 http://www.sqlite 上的文档.org/sqlite.html,部分sqlite3 的特殊命令.

There are many other useful builtin dot commands -- see the documentation at http://www.sqlite.org/sqlite.html, section Special commands to 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 命令的行为(请参阅部分:查询数据库架构).

Note also that SQLite saves the schema and all information about tables in the database itself, in a magic table named sqlite_master, and it's also possible to execute normal SQL queries against that table. For example, the documentation link above shows how to derive the behavior of the .schema and .tables commands, using normal SQL commands (see section: Querying the database schema).

这篇关于如何在 SQLite 中查看表的结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 01:35