0

how to search the whole database for a column name in sqli.

Suppose we have 160 tables with many columns i want to look for animals column inside the database. how would i do that. I have seen couple of examples here mostly they search the column name if the table name is known. but what if i dont know the table itself..??

table 1, table 2..... table 160 and i am looking for "animal" column in the whole database.

i tried if the table is known its working

SELECT * FROM TABLE_NAME WHERE COLUMN_NAME='animal'
Gabf Hann
  • 350
  • 4
  • 16
  • Possible duplicate of http://stackoverflow.com/questions/5648420/get-all-columns-from-all-mysql-tables – NMK Oct 14 '14 at 09:50

2 Answers2

1

Query

SELECT table_name
FROM INFORMATION_SCHEMA.COLUMNS
WHERE column_name='animal';

Read about INFORMATION_SCHEMA here

Ullas
  • 11,450
  • 4
  • 33
  • 50
0

JDBC has a vendor independant solution: DatabaseMetaData.getColumns.

public static void processColumn(Connection con, String column) throws SQLException {
    DatabaseMetaData metadata = con.getMetaData();
    String catalog = null;
    String schema = null;
    String table = null;
    String columnPattern = column;
    try (ResultSet rs = metadata.getColumns(catalog, schema, table, columnPattern)) {
        System.out.printf("Table %s%n", rs.getString("TABLE_NAME"));
    }
}

null serves as wildcard.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138