473,386 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

find table name from a given record

32
I am in the process of normalizing and re-creating a database that was a total maintanence mess. Currently the database has 640 tables. each table is an assembly and contains the data of its sub parts. Now I have created a new database that will incorporate only a hand full of tables.
1 for the part info
1 for assembly reference
1 for category info
1 for category reference
etcetc...

What I would like to do create a query that will search the old database for the table assembly part numbers, given a sub-assembly part number.

so for instance I have the part LH1890 I would like to find all of the assemblies that part belongs to, I would need the table name.

I read on the mysql forums that you can do this according to a specific column, but I need it to search the specific value of a given column....

http://dev.mysql.com/doc/refman/5.0/en/information-schema.html
Oct 2 '07 #1
1 1771
Atli
5,058 Expert 4TB
Hi.

As far as I can see (atm) your best bet would be to create a script to search each table for the part.

Something like:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. # Connect to database
  3. $db = new mysqli("host", "user", "pword", "db");
  4. if(mysqli_connect_errno()) 
  5.   echo "Connection failed: ". mysqli_connect_error();
  6.  
  7. # Find all table names
  8. $sql = "SHOW TABLES";
  9. $result = $db->query($sql);
  10. $tables = array();
  11. while($row = $result->fetch_row()) {
  12.   $tables[] = $row[0];
  13. }
  14.  
  15. # Search each table
  16. $searchResults = array();
  17. foreach($tables as $table) {
  18.   $sql = "SELECT id FROM $table WHERE part = 'partno'";
  19.   $result = $db->query($sql);
  20.   if($result and $result->num_rows == 1) {
  21.     $searchResults[] = $table;
  22.   }
  23. }
  24.  
  25. # Do something else with results
  26. print_r($searchResults);
  27. ?>
  28.  
Oct 3 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Christian Höhener | last post by:
Hi I have a given attributvalue of a specific attribut (sys_obid=81653) which occurs in multiple tables. Now, I should know the tablename of the table in which this attribut occurs. Which...
2
by: Daniel | last post by:
I use an Access database to basically take data exports, import them, manipulate the data, and then turn them into exportable reports. I do this using numerous macros, and queries to get the data...
28
by: Lee Rouse | last post by:
Hello all, This is going to be a rather lengthy "question". I have an Access 2k database, separated front end/back end. Front end copies are on about 30 workstations and used frequently during...
4
by: Aaron Smith | last post by:
Dim dv As DataView = New DataView(FacilitiesDS1.Facilities, "", "ID ASC", DataViewRowState.CurrentRows) Dim iPos As Integer = dv.Find(dr.Item("ID")) Me.BindingContext(FacilitiesDS1,...
3
by: sean | last post by:
I have a table with fixed row of records SORTED by DATE using ADO pagination method. The user can click a link in one table cell and go to another page to modify the record. Once the updated record...
117
by: phil-news-nospam | last post by:
Is there really any advantage to using DIV elements with float style properies, vs. the old method of TABLE and TR and TD? I'm finding that by using DIV, it still involves the same number of...
0
by: André | last post by:
Hi, Still the same (unsolved problem), but other error now. I have a detailsview for inserting data, and a dropdownlist which selectedValue must be used to fill one of the field of the...
9
by: Oonz | last post by:
Hi Friends, How can we insert records in sorted order like consider a table No Name Phone 1 test1 12345 1 test1 23455 2 test2 68638
5
by: Harlequin | last post by:
Hi there, I'm something of a newcomer to MS Access so it's more than likely that my question is extremely elementary. I have a form whose record source is a single table in my database. It's...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.