0

enter image description here

Hello, I have this simple diagram showing two tables, event table and guest table.

I created an event which has id of 1 and there are 3 guests for event id of 1. If I want to reuse the same guests for event id 2 and 3, how do I relate them using a foreign key? What if I want to remove Joe from the event 2, how do I do it so that it won't delete Joe from the table because Joe is needed for event 1? I am confused and I don't know if my question is clear enough. Do I need to add some columns to help this out?

  • In shown schema you will have more than one record for each guest - one record for each event. Removing the record with name=Joe and event=2 will not remove the record with name=Joe and event=1. And you can NOT "reuse" records. – Akina Jan 29 at 18:19
  • One user matched many events. One event matched many users. The relation is M:N. It needs 3 tables - users (id, name, etc.), events (id, name, etc.), and users_events (isers_id, events_id). The last table has 2 FKs - to each another table. – Akina Jan 29 at 18:21
  • Thank you so much. Your suggestion could be the solution for me and I will try it out. – calvert Jan 29 at 18:33
  • @Akina Thank you, it works. – calvert Jan 30 at 2:34
0

uses a third table that will link the Event table to the Guest table :

enter image description here

  • Thank you, Steph74. I will try this out tonight and mark this as the solution. – calvert Jan 29 at 21:04

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.