Skip to content

Instantly share code, notes, and snippets.

@lewdev
Created April 4, 2019 21:42
Show Gist options
  • Save lewdev/6312476ff9461e58f7416a391dee2ccb to your computer and use it in GitHub Desktop.
Save lewdev/6312476ff9461e58f7416a391dee2ccb to your computer and use it in GitHub Desktop.
SQLite query to get column data by rows with additional information about each column.
SELECT
m.name AS table_name,
p.cid AS col_id,
p.name AS col_name,
p.type AS col_type,
p.pk AS col_is_pk,
p.dflt_value AS col_default_val,
p.[notnull] AS col_is_not_null
FROM sqlite_master m
LEFT OUTER JOIN pragma_table_info((m.name)) p
ON m.name <> p.name
WHERE m.type = 'table'
AND m.name LIKE '%QUERY TABLE NAME HERE%'
ORDER BY table_name, col_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment