dt614037527 2018-11-06 14:06
浏览 36

如何动态获取,更新,插入以使表的数量保持很小

I'd like to design a database. I have questions and I'll try to explain them the best way.

1) one has told me that if you don't want many details about the project or if you don't want to do many things by hand, go for dynamic idea which means that you don't have a table with columns, but you have a table which has columns as rows. is this a good approach? is it worth it?

2) if you have less tables, it's easier to scale. why is that?

3) Let's say I go for dynamic idea. so what I came up with is that I've created 3 tables. these 3 tables will always be the same and always be helpful for other tables that use dynamic idea. how? here is how.

form_types table

+----+------------+
| id | input_type |
+----+------------+
|  1 | select     |
|  2 | input      |
|  3 | bool       |
+----+------------+

dynamic_columns table

+----+---------------+--------------+
| id |     name      | form_type_id |
+----+---------------+--------------+
|  1 | year_of_issue |            1 |
+----+---------------+--------------+

type_values table

+----+-------------------+-------+
| id | dynamic_column_id | value |
+----+-------------------+-------+
|  1 |                 1 |  1996 |
|  2 |                 1 |  2005 |
|  3 |                 1 |  2008 |
+----+-------------------+-------+

now I can use these tables to add cars and fetch cars from database dynamically, but to make it work for cars, I'll use these 3 tables and also I had to add another 3 tables for cars.

cars

+----+
| id |
+----+
|  1 |
+----+

column_transport_type

+---------------+-------------------+
| dynamic_column_id | transport_type_id |
+---------------+-------------------+
|             1 |                 1 |
+---------------+-------------------+

car_columns_value

+----+--------+-------------------+-------+
| id | car_id | dynamic_column_id | value |
+----+--------+-------------------+-------+
|  1 |      1 |                 1 |  1996 |
+----+--------+-------------------+-------+

So let’s talk about the below 3 tables. From user, I get the transport_type_id that is written in column_tranport_type table. Let’s say I got transport_type_id as 1. with 1, I get that dynamic_column_id is equal to 1.. I go to dynamic_columns table and find all that has id equal to 1. so it’s year_of_issue. Then I check if year_of_issue is select or input and if it’s select, I also return select values with the column name “year_of_issue” to front-end so that after returning this information, I for-each loop that information and create the form dynamically. When he enters information into those columns that I dynamically fetched, I use car_columns_value table to put the values there. Do you understand my scenarion?

Is this the great way of how I should do this kind of things dynamically? My worries are that for each kind of things(car or ship) that I want it to work dynamically, I have to create 3 more tables. 3 tables are default and for every dynamic business logic(car,shop, ship) I need another 3 tables and another 3 tables and so on. As you know number of tables will grow and maybe that’s not dynamic so far. I was told that dynamic is good when you shorten the number of tables so that you can scale better. Just give me your ideas. Should I follow my approach or what should I do?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘