Sql 对于这种情况,最好的数据库建模方法是什么?
对于这种情况,什么是正确的数据建模 在我的例子中,一个应用程序有多个版本,每个版本都有多个计划。因此,每个客户都有一个使用应用程序的合同 基表:Sql 对于这种情况,最好的数据库建模方法是什么?,sql,database,Sql,Database,对于这种情况,什么是正确的数据建模 在我的例子中,一个应用程序有多个版本,每个版本都有多个计划。因此,每个客户都有一个使用应用程序的合同 基表: customers ------------------------------ id int PK INC name string applications ------------------------------ id int PK INC name
customers
------------------------------
id int PK INC
name string
applications
------------------------------
id int PK INC
name string
editions
------------------------------
application_id int PK FK
id string PK (e.g: "STANDARD", "ADVANCED", "PROFESSIONAL")
plans
------------------------------
application_id int PK FK
edition_id string PK FK
id string PK (ex: "MONTHLY", "YEARLY")
contracts
------------------------------
customer_id int FK
application_id int FK
edition_id string FK
plan_id string FK
id int PK INC
editions
------------------------------
application_id int PK FK
id int PK
name string (ex: "STANDARD", "ADVANCED", "PROFESSIONAL")
plans
------------------------------
application_id int PK FK
edition_id int PK FK
id int PK
name string PK (ex: "MONTHLY", "YEARLY")
contracts
------------------------------
customer_id int FK
application_id int FK
edition_id int FK
plan_id int FK
id int PK INC
editions
------------------------------
application_id int FK
id int PK INC
name string (ex: "STANDARD", "ADVANCED", "PROFESSIONAL")
plans
------------------------------
edition_id string FK
id int PK INC
name string (ex: "MONTHLY", "YEARLY")
contracts
------------------------------
customer_id int FK
plan_id int FK
id int PK INC
第一种选择:
选项#1:
customers
------------------------------
id int PK INC
name string
applications
------------------------------
id int PK INC
name string
editions
------------------------------
application_id int PK FK
id string PK (e.g: "STANDARD", "ADVANCED", "PROFESSIONAL")
plans
------------------------------
application_id int PK FK
edition_id string PK FK
id string PK (ex: "MONTHLY", "YEARLY")
contracts
------------------------------
customer_id int FK
application_id int FK
edition_id string FK
plan_id string FK
id int PK INC
editions
------------------------------
application_id int PK FK
id int PK
name string (ex: "STANDARD", "ADVANCED", "PROFESSIONAL")
plans
------------------------------
application_id int PK FK
edition_id int PK FK
id int PK
name string PK (ex: "MONTHLY", "YEARLY")
contracts
------------------------------
customer_id int FK
application_id int FK
edition_id int FK
plan_id int FK
id int PK INC
editions
------------------------------
application_id int FK
id int PK INC
name string (ex: "STANDARD", "ADVANCED", "PROFESSIONAL")
plans
------------------------------
edition_id string FK
id int PK INC
name string (ex: "MONTHLY", "YEARLY")
contracts
------------------------------
customer_id int FK
plan_id int FK
id int PK INC
第二种选择:
选项2:
customers
------------------------------
id int PK INC
name string
applications
------------------------------
id int PK INC
name string
editions
------------------------------
application_id int PK FK
id string PK (e.g: "STANDARD", "ADVANCED", "PROFESSIONAL")
plans
------------------------------
application_id int PK FK
edition_id string PK FK
id string PK (ex: "MONTHLY", "YEARLY")
contracts
------------------------------
customer_id int FK
application_id int FK
edition_id string FK
plan_id string FK
id int PK INC
editions
------------------------------
application_id int PK FK
id int PK
name string (ex: "STANDARD", "ADVANCED", "PROFESSIONAL")
plans
------------------------------
application_id int PK FK
edition_id int PK FK
id int PK
name string PK (ex: "MONTHLY", "YEARLY")
contracts
------------------------------
customer_id int FK
application_id int FK
edition_id int FK
plan_id int FK
id int PK INC
editions
------------------------------
application_id int FK
id int PK INC
name string (ex: "STANDARD", "ADVANCED", "PROFESSIONAL")
plans
------------------------------
edition_id string FK
id int PK INC
name string (ex: "MONTHLY", "YEARLY")
contracts
------------------------------
customer_id int FK
plan_id int FK
id int PK INC
第三种选择:
选项#3:
customers
------------------------------
id int PK INC
name string
applications
------------------------------
id int PK INC
name string
editions
------------------------------
application_id int PK FK
id string PK (e.g: "STANDARD", "ADVANCED", "PROFESSIONAL")
plans
------------------------------
application_id int PK FK
edition_id string PK FK
id string PK (ex: "MONTHLY", "YEARLY")
contracts
------------------------------
customer_id int FK
application_id int FK
edition_id string FK
plan_id string FK
id int PK INC
editions
------------------------------
application_id int PK FK
id int PK
name string (ex: "STANDARD", "ADVANCED", "PROFESSIONAL")
plans
------------------------------
application_id int PK FK
edition_id int PK FK
id int PK
name string PK (ex: "MONTHLY", "YEARLY")
contracts
------------------------------
customer_id int FK
application_id int FK
edition_id int FK
plan_id int FK
id int PK INC
editions
------------------------------
application_id int FK
id int PK INC
name string (ex: "STANDARD", "ADVANCED", "PROFESSIONAL")
plans
------------------------------
edition_id string FK
id int PK INC
name string (ex: "MONTHLY", "YEARLY")
contracts
------------------------------
customer_id int FK
plan_id int FK
id int PK INC
还是其他?
?
还有另一种方法吗?我认为这些方法都不是“最好的”。它们在体系结构中都有一些奇怪的限制。1和2中都有冗余数据。第三个版本仅限于一份合同。但是……我认为第三个是最接近的。当然,这可能会因为过于基于观点而被关闭。离题-属于。但即使这样,“最佳”也没有什么意义,如果你对你的实际模型和你打算如何使用它没有很好的(真正的、完整的)理解。如果需要,可以将其中一个放回去,这是实际使用的dbms的问题。像这样的问题不属于dba。这是一个数据库设计问题,而不是管理问题。