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.
that way you can do the delete and check in one step. You can then select the record you wanted to delete directly afterwards (or use the resulting rowcount()) to inform the user if the delete was successful of not.