----- Original Message ----- From: "Bing Du" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, September 10, 2004 10:52 AM Subject: search a field in all the tables?
> Many times I need to do this. I know the name of a specific field. But I > don't know which table has this field. There usually are a lot tables in > one database. So the question is how I can find out which table or tables > has this field? If it can be done within one database, can it also be > done across all the databases? > > Thanks in advance for any help. > Do you know Java? If you use the getColumns() method in the DatabaseMetaData interface, you can determine the names of columns in a MySQL database even if you don't know the name of the table. You can even specify that you only want column names whose name follows a particular pattern. For example: ResultSet rs = dbMeta.getColumns(myCatalog, "%", "%", "C%"); requests information about all of the columns in your database where the column name starts with "C" and you don't know or care about the schema name or the table name. I just knocked together a little sample Java program to prove that this works. I'm not sure if there is any other way to get the information. In DB2, the database that I know best, you can query the database catalog from the command line or a program just like you can with a regular user table and determine column names that way; I haven't figured out any way to do that in MySQL. If anyone can tell me any way to query the catalog tables in MySQL directly, rather than via Java, I'd love to know! (I tried looking in the MySQL manual but couldn't find anything like that.) Rhino -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]