/* Show all key/indexed columns and their referenced table/column (if any)    */
/* Performing Cartesian joins between sqlite_master and many pragma functions */ 

SELECT sm.name AS table_name, fk."from" AS column_name, 
      'FOREIGN KEY' AS constraint_type, null AS constraint_name, null AS ordinal_position,  #Get all foreign keys 
       fk."table" AS ref_table_name, fk."to" AS ref_column_name
FROM sqlite_master sm
JOIN pragma_foreign_key_list(sm.name) fk 

UNION

SELECT sm.name AS table_name, tbl.name AS column_name, 
      ' PRIMARY KEY', 'PRIMARY', null, null, null                                           #Get all primary keys
FROM sqlite_master sm
JOIN pragma_table_info(sm.name) tbl 
WHERE pk=1

UNION 

SELECT sm.name AS table_name, xInfo.name AS column_name,  
       CASE xList."unique" WHEN 1 THEN 'UNIQUE INDEX' ELSE 'INDEX' END,                     #Get all indexes        
       xList.name AS constraint_name, seqno AS ordinal_position,
       null, null
FROM sqlite_master sm
JOIN pragma_index_list(sm.name)    xList    
JOIN pragma_index_info(xList.name) xInfo 
ORDER BY 1,3,4,5,2;