MySQL, check if foreign key is assigned to any table
P粉993712159
P粉993712159 2023-08-17 12:51:10
0
1
463
<p>I have a table called <code>files</code> Additionally, I have over 100 tables in which I use associations/foreign keys <code>file_id</code></p> <p>How do I get all <code>files</code> that do not have an existing association (that is, the file is not attached to any table)? </p>
P粉993712159
P粉993712159

reply all(1)
P粉566048790

I usually do this in bash (it might be possible to use SQL, but I'm not sure which table)

table_names=`echo "show tables"|mysql database_name -q -s|grep -v "show tables"`
for table in $table_names
do
  echo $table
  mysqldump database_name $table |grep file_id
done;

Then you will see something related to file_id in each table.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!