MySQL - Find entries that refer to a specified index.
Posted
by Conor H
on Stack Overflow
See other posts from Stack Overflow
or by Conor H
Published on 2010-04-04T15:46:26Z
Indexed on
2010/04/04
15:53 UTC
Read the original article
Hit count: 191
Hi,
So I have a booking system where I have a 'lesson_type' table with 'lesson_type_id' as PK. I have a constraint in place here so I can't delete a lesson_type if there are bookings made for that lesson_type.
I would like to be able to determine if this lesson_type_id is being referred to by any entries in the bookings table (or any other table for that matter) so I can notify the user gracefully. i.e. not have a mysql error be thrown when they try and delete a record.
What kind of query would I use for this?
Thanks.
© Stack Overflow or respective owner