How to design tables to take into account changes in prices for services. There are two tables:
mysql> SHOW COLUMNS FROM services; +---------------+----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+----------+------+-----+---------+----------------+ | service_id | int(11) | NO | PRI | NULL | auto_increment | | lesson_id | int(11) | NO | MUL | NULL | | | service_end | datetime | NO | | NULL | | | service_start | datetime | NO | | NULL | | +---------------+----------+------+-----+---------+----------------+ mysql> SHOW COLUMNS FROM lessons; +--------------+---------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------------+---------------+------+-----+---------+----------------+ | lesson_id | int(11) | NO | PRI | NULL | auto_increment | | lesson_name | varchar(60) | NO | UNI | NULL | | | lesson_worth | decimal(20,4) | NO | | NULL | | +--------------+---------------+------+-----+---------+----------------+ It is necessary that the prices in the services table be kept until they are changed, if any, that is, price changes for lessons did not affect the available lines in services .
Found a solution with a table that stores the history of price changes (if there is a better offer), then what price should be stored in services : from the history table or from lessons ?
UPD :
Came to this model, based on the answer.
mysql> SHOW COLUMNS FROM services; +---------------+----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+----------+------+-----+---------+----------------+ | service_id | int(11) | NO | PRI | NULL | auto_increment | | lesson_id | int(11) | NO | MUL | NULL | | | service_end | datetime | NO | | NULL | | | service_start | datetime | NO | | NULL | | +---------------+----------+------+-----+---------+----------------+ mysql> SHOW COLUMNS FROM lessons; +-------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+----------------+ | lesson_id | int(11) | NO | PRI | NULL | auto_increment | | lesson_name | varchar(60) | NO | UNI | NULL | | +-------------+-------------+------+-----+---------+----------------+ mysql> SHOW COLUMNS FROM worths; +------------+---------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+---------------+------+-----+---------+-------+ | worth_id | int(11) | NO | PRI | NULL | | | lesson_id | int(11) | NO | MUL | NULL | | | worth | decimal(20,4) | NO | | NULL | | | worth_date | datetime | NO | | NULL | | +------------+---------------+------+-----+---------+-------+
servicesis the ultimate service that stores an occupation, its beginning, and its end.lessons- classes, name and price. - Pakhan