M
M
Millerish2017-10-24 17:10:23
MySQL
Millerish, 2017-10-24 17:10:23

How to properly build a MySQL table?

Good time of the day!
I am writing a small service for school (React+PHP+MySQL). I will need to store the schedule for each class. The number of classes is unknown. I want the simplest possible structure.
So far, the simplest brew that came to mind is this:

  • id - index
  • Class name - text
  • Monday - text - here, separated by commas, all lessons
  • Tuesday - text - here, separated by commas, all lessons
  • Wednesday - text - here, separated by commas, all lessons
  • Thursday - text - here, separated by commas, all lessons
  • Friday - text - here, separated by commas, all lessons
  • Saturday - text - here, separated by commas, all lessons
  • Sunday - text - here, separated by commas, all lessons

The advantage of this option is that the structure is very simple and flexible, the minus is an additional operation to parse the string to get lessons.
How would you organize such a base?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rsa97, 2017-10-24
@Rsa97

classes (id, number)
subjects (id, name)
teachers (id, full name)
timetable (class_id, subject_id, teacher_id, week_day, lesson_number)
adjustments (class_id, subject_id, teacher_id, date, lesson_number)

A
Alex-1917, 2017-10-24
@alex-1917

Considering three factors:
1. Your statement that the application is planned to be small
2. Such an application will be really small, you are unlikely to make it for school No. 63 in Tyumen, where 26 classes were enrolled this year, even the 1st!))
3 There are really only seven days of the week, there won't be less of them, there won't be more of them, I think it's stupid to start a table for the days of the week, then it's better to create an ENUM type field for this.
All other arguments against - you will not learn how to do joins and queries to several tables in one sitting, you will not care about the possibility of speeding up a query by returning part of the calculations to the php interpreter, etc.
Choose yourself)))
59ef5ec0c672e680241036.jpeg

V
Vladimir Kuts, 2017-10-24
@fox_12

And what kind of sampling is supposed to be done? It can be simplified altogether.
Two fields, class and schedule. Schedule - store in json representation, something like:

{
  "понедельник": {
                "0": "",
                "1": "Алгебра",
                "2": "Геометрия"
  },
  "вторник": {
  ...
  },
  ...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question