简体   繁体   中英

SQL foreign key to multiple tables

I am creating a health and safety app for 30 different forms; for every question in each document, I need to allow users to add multiple images and enable them to add various actions.

Furthermore, each form needs to be linked to a project.

So far, I have created a Project table, a Site_Weekly_Inspection table (one of the forms) with a foreign key to the project, an Action table with a foreign key site_weekly_inspection and an image table with a foreign key to site_weekly_inspection.

Additionally, in the action and image table, I used action_category and image_category to be able to link the images and actions to the individual questions.

My database so far

I don't want to create a separate image and action table for each form. What would be the MOST CORRECT way of making this database?

Thanks in advance for any suggestions.

You will need table(s) in the middle.

  1. Inspection_Action table - lists all possible actions Inspection_Action_id

  2. Inspection_Image table (or just Image )- lists all images Inspection_Image_id (PK)

  3. Site_Weekly_Inspection_Action Site_Weekly_Inspection_Action_id Inspection_Action_id (FK points to Inspection_Action)

  4. If only one image per site / weekly add to Site_Weekly_Inspection table Inspection_Image_id (FK points to Inspection_Image)

  5. If more than one image per site /weekly add table Site_Weekly_Inspection_Images Site_Weekly_Inspection_Image_id (PK) Inspection_Image_id (FK points to Inspection_Image)

You will need to figure out how to share images and actions in UI

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM