简体   繁体   中英

How do I structure this database?

I'm a newbie making a really simple app in rails, but I have no experience structuring databases...Can you tell me if there's an advantage to either way presented below or if there's a better third way to set it up?

The students will be asked two questions on a form

  1. "Which courses do you think students will likely fail?" (Check all that apply)

Math, English, French, Science

  1. "Which courses do you think students will likely pass?" (check all that apply)

Math, English, French, Science


For the database, do I create a "pass" and a "fail" column of type "string". So that, for example, for User1

"Pass" might have Math and English, and

"Fail" might have Science

and for whatever reason, he didn't offer an opinion on French..


or should I make columns "Math" "French" "Science" "English" of type 'string' and then have "pass" or "fail" entered into each column

What is the better way to organize it?

I'd probably create 4 tables, User, Course, ExpectedResult and UserCourseExpectedResult which links the first 3 tables together.

This provides future flexibility in case your expected results include additional values.

The table structures would be along the lines of

User
   UserId
   Name
   ...

Course
   CourseId
   Name
   ...

ExpectedResult
   ExpectedResultId
   Description

UserCourseExpectedResult
   UserId
   CourseId
   ExpectedResultId

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