简体   繁体   中英

database design dynamic table

i have fieldnames, f1, f2, f3, f4, f5, f6. These field names are to be shown depending on the values of other field names.

Example, f3 has to be shown, if f2 value is "COND1" f4 has to be shown, if f3 value is "COND

the field names are not fixed, they can be added, edited and deleted. The values COND1, COND etc are also not fixed, they can be changed.

Can someone point how to design the database Thanks

Dynamic table for RDBMS is an anti-pattern. Do not do that.

Maybe NoSQL databases could be more appropriate for your use case - that's what they're made for.

Or, if you insist on relational, then you need to make your database accomodate dynamic structure - something like key-value tables and manage the structure yourself. Ie tables structure would keep both structure metadata and data.

In case your structure is simple enough, you want just one additional table, with a composite key - the original ID, and name of the parameter.

If your only conditions are field == value then I would consider this:

| Field Table |
|-------------|
| id          |
| fieldName   |
|-------------|

| Conditional Table |
|-------------------|
| id                |
| comparisonField   |
| comparisonValue   |
| displayField      |
|-------------------|

So condition 1 would have values 1, 2, "COND1", 4 to show field 4 if field 2 == "COND1"

If you wanted other comparisons, less than, greater than, etc. Also have a table of comparators to link to the Conditional table.

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