If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Which tables has reference to foreign key id?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-21-08, 16:13
jmut jmut is offline
Registered User
 
Join Date: Mar 2004
Location: Bulgaria
Posts: 22
Question Which tables has reference to foreign key id?

Hi, let's say I have table1(t1_a,t1_b and table2(t2_a,t2_b) table2 has columna t2_b that references t1_a with foreign key... both tables InnoDB of course.
So I want to delete a record from table1 - but I would like to know if t1_a is somewhere referenced so I can give the user a warning..that this thingy is still in use......
The approach of trying to delete...and parsing the error is not really an option I think. So besides, doing several selects(for each table that references t2_a) someone knows faster approach for this ?
Looked also in information schema..but no such info provided there.
Thanks
Reply With Quote
  #2 (permalink)  
Old 07-21-08, 19:21
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by jmut
Looked also in information schema..but no such info provided there.
try the information schema KEY_COLUMN_USAGE table
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 07-22-08, 03:09
jmut jmut is offline
Registered User
 
Join Date: Mar 2004
Location: Bulgaria
Posts: 22
Quote:
Originally Posted by r937
try the information schema KEY_COLUMN_USAGE table
Well, I did and only info I can get from there is which tables reference specific column I am interested in... but with this I am still left with N selects for each such table to determine if id is used.... This is my best shot so far... I was thinking to create view or something of that....but view is no performance booster so no clue.....thing is I'd like to be as quick as possible....
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On