0

I like to build a query which can search in complete data base in all tables.

Ex. Search String: 9049 Now in result I need search result from all table where this string matches. Simply I can't write LIKE to all field of table.

Thanks In Advance.

prashant.fepale
  • 547
  • 1
  • 8
  • 26

2 Answers2

0

You could do an SQLDump of the database (and its data) then search that file. or You can peek into the information_schema table. It has a list of all tables and all fields that are in a table. You can then run queries using the information that you have gotten from this table.

Santosh Ram Kunjir
  • 1,074
  • 1
  • 12
  • 23
0

You could first read out all the tables:

SELECT table_name FROM information_schema.tables WHERE table_schema = 'yourdatabasename'

and then loop through all the tables and get all the columns:

SELECT column_name FROM information_schema.columns
WHERE table_schema = 'yourdatabasename' AND table_name = 'thetablenamefromyourloop'

and then build a dynamic statement thats builds the WHERE clause based on your searchterm.

or to get just all the information just read out everything. This contains all the information about all the tables and columns, which might be useful to just search in all the varchar and text fields etc.

SELECT * FROM information_schema.columns
WHERE table_schema = 'yourdatabasename'
ST2OD
  • 705
  • 1
  • 5
  • 15