Dynamic Attribute Table
The most common practice is forum.
Currently, many forums have real estate forums. Then the post of the House will have some attributes.
For example, in a community, there are several rooms and halls, but not all posts require this. In the future, users may also define some types of attributes.
My most basic design is
For a simple second-level structure, we use two tables.
Attribute
ID
Name, such as the cell location
Displayorder (sort ID)
Controltype (a type) is used to display dropdownlist checkbox or colorpicker during foreground control.
Attributeitem
ID
Attributeid
Name
Displayorder
Attributevalues
ID
Attributeitemid xx id of the residential area
Postid (the ID forum of a major table is the topic ID. If it is a product, it is productid ...)
Such an attribute is an attribute. For example, attributeitem has a red blue green attributevalues which is not associated with a specific color.
Then, if it is a relatively large system, such as a forum, some attributes need to be classified into a forum, when this forum posts, the relevant attribute will be displayed so that users can select.
But when users want to add something for themselves? For example, the structure above the price is not suitable, because you are unlikely to define all the prices.
Attribute
ID
Name
Displayorder
Type (Int or string decimal ...)
Attributedefavalue Value
Attributeid
Defaultvalue
Displayorder
Attributevalues (many to many)
ID
Attributeid
Postid (the ID forum of a major table is the topic ID. If it is a product, it is productid ...)
Numbervalue (decimal type, convert datetime to number type)
Strvalue
If it goes further, attributevalues becomes
Attributestringvalues
ID
Attributeid
Postid (the ID forum of a major table is the topic ID. If it is a product, it is productid ...)
Strvalue
Attributedecimalvalues
ID
Attributeid
Postid (the ID forum of a major table is the topic ID. If it is a product, it is productid ...)
Decimalvalue
Attributedatetimevalues
....
In this way, the attribute is the color attributedefaultvalue which has the red green blue
Which side of attributevalues is the direct value?
It seems that this structure is called EAV.