Skip to content

Instantly share code, notes, and snippets.

@barryparkin
Last active February 13, 2024 11:44
Show Gist options
  • Save barryparkin/9089296 to your computer and use it in GitHub Desktop.
Save barryparkin/9089296 to your computer and use it in GitHub Desktop.
(sqlite) Find table in database by field name
SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME like '%{{fieldname}}%'
AND TABLE_SCHEMA = {{Database}};
@grodriguece
Copy link

In my case sqlite_master instead of INFORMATION_SCHEMA was available for sqlite3:

SELECT DISTINCT name FROM sqlite_master
WHERE sql like '%fieldname%';

@ixzh
Copy link

ixzh commented Mar 8, 2021

WHERE sql like

can you explain the sql here? it's not any field name right?

@grodriguece
Copy link

Only fieldname has to be included. Query result will show all the tables where there is a column name equal to fieldname.
fieldname

@ixzh
Copy link

ixzh commented Mar 8, 2021

Only fieldname has to be included

I just realised sqlite_master is a special table where sql is the last column with the CREATE statement text. Thanks !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment