I am learning SQL, using SQLite. I'm seeing how many-to-many relationships work between tables that use primary key and foreign key.
I have three tables:
contacts
, which has the following columns: contact_id (primary key), first_name, last_name, email and phone.
groups
, which has the following columns: group_id (primary_key) and name.
contact_group
, (my relational table) with columns: contact_id (primary key and associated with foreign key to contact_id of contacts
) and group_id (primary key and associated with foreign key to group_id of groups
).
I can enter data in contacts
tables in this way:
insert into contacts (first_name, last_name, email, phone)
values
('jon','sanchez', '[email protected]','4433');
And in groups
like this:
insert into groups (name)
values
('clase')
But how do I fill in the relational table contact_group
? How do I tell you which contact is in each group? How do I say that Jon belongs to the Class group?