How I could receive SQLite database layout?
For backward compatibility purpose I would like to know a layout of my database, i.e. which tables are incorporated in my database, for each table which columns are included, etc.
The sqlite_master
table contains only table information. Theoretically I have acces开发者_JS百科s to this metadata information through SQLite API such as sqlite3_column_database_name
, sqlite3_column_table_name
, sqlite3_column_origin_name
.
Could I have a direct SQL query to receive this data or it is stored internally?
Well it's not stricly speaking SQL, but it is accessible as SQL in all sqlite implementations I know of:
http://www.sqlite.org/pragma.html#pragma_table_info
An example:
sqlite> .headers on
sqlite> .mode column
sqlite> CREATE TABLE foo (id INTEGER PRIMARY KEY AUTOINCREMENT, text1 TEXT NOT NULL, text2 TEXT, boolean1 BOOLEAN NOT NULL);
sqlite> pragma table_info('foo');
cid name type notnull dflt_value pk
---------- ---------- ---------- ---------- ---------- ----------
0 id INTEGER 0 1
1 text1 TEXT 1 0
2 text2 TEXT 0 0
3 boolean1 BOOLEAN 1 0
I would like to receive “the description of what tables there are”
I'm mot sure what you mean by that.
You can get the SQL statements necessary to re-create your schema with .schema
.
sqlite> .schema
CREATE TABLE a (n integer);
CREATE TABLE b (n integer);
Also, .dump
will give you those same SQL statements, and it will add INSERT statments to reproduce the data.
If part of what you want is just a list of tables, then .tables
will do that for you.
Documentation (scroll down to "Special commands . . .")
精彩评论