Search code examples
mysqldatabase-normalization

SQL many to many relation, multiple tables


Hey so i have been doing alot of reading and i am finding many conflicting ways to link my tables. hoping someone can help me put the foreign keys in the correct places.

tables -

customers: customer_id(primary), customer_name ;

employee: employee_id(primary), employee_name ;

appointments: appointment_id(primary), appointment_date ;

inventory: inventory_id(primary), item ;

so i have primary key for each table but i need to link 1 customer to the appointments table and multiple employees to the appointments tables.

the inventory table must link to the appointments tables.

Here is an example, customer sets an appointment then employee(s) fills appointment. during that appointment the customer buys an item(s).

it is sufficent enough to just show the item with the appointment. the item does not need to link to the customer.

thank you for help. i was thinking i needed to make a 5th table to fill with all the keys but im really unsure and the tables have alot more information in them than i posted above. would be alot of trial an error to then see if not work one of the ways i need.


Solution

    1. You should add customer_id foreign key to the appointments table
    2. You should create table appointment _employee:id (primary key),appointment_id(foreign key), employee_id(foreign key)
    3. You should create table appointment_inventory:appointment_id, inventory_id