简体   繁体   中英

ER diagram to Relational Database Tables

I have an ER diagram, shown below.

在此处输入图片说明

I need help to create a relational database. To explain the ER, I have Services and service has 1-6 objectives and each objective can match up to 1-8 goals. So the relationship between services and objectives is 1 to many (1-6) and the relationship between objectives is also 1 to many (1-8).

This is what I have so far (* = primary key)

  • Goals: (GID*, Goal_statement)
  • Objectives (OID*, Objective_statement)
  • Services (SID*, Service_Name)

I have to create an PHP script and display the services and then when I click a service, I will be redirected to show its objectives and the related Goals to the objectives. How can I show this? Do I have to create a table for MATCH and HAVE?

No, you don't need joining tables in this case. One service can have many objectives, and one objective can have many goals. That's two 1:many relationships, so all you need is a foreign key in each of the "has" tables.

Thus, you'll also need these columns:

  • service.objective_id (so a service can specify which objective it is related to)
  • objective.goal.id (so an objective can specify which goal it is related to)

To create your web application, you'll need to write some SQL, which you can decide before you write the PHP. It sounds like you will need:

  • A list of services (simple SELECT )
  • A list of objectives and their goals, given a service ID (a SELECT with an INNER JOIN )

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