I have a problem with the design of the database, which I have been doing for some time, but cannot get the correct answer. Let's say we have two tables house_schema and house as follows:
house_schema { id big int, house_height int, house_width int, house_decoration vchar(1024), build_date timestamp, primary key id, } house { id big int, owner vchar(255), price big int, house_schema_id big int, primary key id, foreign key fk_house_house_schema_id (`house_schema_id`) reference `house_schema`.`id` }
The house_schema table stores some of the physical attributes of house . In the software user interface, users select a scheme, then click the Create button. The house is built and stored in the house . To describe how the house should be built, there are several other tables, for example house_schema .
In a simple design, the foreign key seems to work well. However, this causes a problem when the builder decides to remove the scheme, which, in their opinion, is outdated. There are already some houses built from the circuit, and the foreign key does not allow you to remove it. If we change the foreign key to DELETE ON CASCADE , then these houses will lose the information from which it was built.
What is the best design template to solve this problem? What I can imagine is to have a duplicate house_schema table, once the house is built, copy the row in house_schema to the duplicate table.
But this leads to a lot of duplicate tables in the database, as I have several similar tables with house_schema . This seems to violate database normalization rules.
Does anyone have a good idea?