How to create a junction table in mysql to link two tables?

2023/03/27 2:49

If you have 2 tables in mysql. One table for group and another table for contacts. The 2 tables have many relationships. What is the | vay to link the two table then storing data?

CREATE TABLE group_contacts (

group_id INT NOT NULL,

contact_id INT NOT NULL,

PRIMARY KEY (group_id, contact_id),

FOREIGN KEY (group_id) REFERENCES groups (id),

FOREIGN KEY (contact_id) REFERENCES groups (id),

);

Back to top