snippetsqlMinor
How to read metadata from Sqlite database
Viewed 0 times
readsqlitedatabasehowfrommetadata
Problem
Sometimes I use SQLite database but it's quite common that I don't know anything about its structure.
I need to retrieve all metadata like the name of a database or table, the data type of a column, primary keys, foreign keys, or access privileges.
MSSQL has information_schema for this purpose but is there something similar for SQLite?
I need to retrieve all metadata like the name of a database or table, the data type of a column, primary keys, foreign keys, or access privileges.
MSSQL has information_schema for this purpose but is there something similar for SQLite?
Solution
The equivalent of, for instance, MySQL
and
is also useful. Most of the time, however, I simply use
which outputs the SQL definition of the table or view, even with the original comments (exactly the same as
describe t1; isPRAGMA TABLE_INFO(t1);and
SELECT * FROM sqlite_master WHERE tbl_name = 't1';is also useful. Most of the time, however, I simply use
.schema t1which outputs the SQL definition of the table or view, even with the original comments (exactly the same as
SELECT sql FROM sqlite_master WHERE..., with less typing. .sch works too.)Code Snippets
PRAGMA TABLE_INFO(t1);SELECT * FROM sqlite_master WHERE tbl_name = 't1';Context
StackExchange Database Administrators Q#169246, answer score: 9
Revisions (0)
No revisions yet.