У меня есть три таблицы mysql. Таблицы уже созданы.Как определить ограничения внешнего ключа
Requests - request_id, request_message, user_id
Responses - response_id, response_message, user_id
users - user_id, user_name
Теперь я хочу, чтобы определить ограничения внешнего ключа на том, что, таким образом, что
1. If user_id is not present in Users table, and someone is inserting the data in Requests or Responses for that user_id -- then error
2. If request_id is not present in Requests table, then if someone is inserting in responses table for that request_id -- then error
3. If someone deletes an user_id, all associated requests and responses with that user_id should be deleted automatically.
4. If someone deletes an request_id, all the associated responses with it, should be deleted automatically.
Если я отсутствует какой-либо вещи, пожалуйста, дайте мне знать.
Как достичь этой функциональности?
Благодаря
Devesh