简体   繁体   English

在关系数据库中表示类似规则输入的最佳方式是什么?

[英]What is the best way to represent similar inputs for rules in a relational database?

I am designing a rules database, which takes a number of inputs and determines the appropriate output.我正在设计一个规则数据库,它接受一些输入并确定适当的 output。

There is a set of ~20 input types that are very similar (can be represented with Id, Value) which all drive a set ~20 output types.有一组 ~20 个输入类型非常相似(可以用 Id、Value 表示),它们都驱动一组 ~20 个 output 类型。 Each input type has a number of possible values.每种输入类型都有许多可能的值。 Each output type has a number of possible values as well.每个 output 类型也有许多可能的值。

An example rule would be InputTypeA + InputTypeB determines OutputTypeA or InputTypeA determines OutputTypeB .一个示例规则是InputTypeA + InputTypeB determines OutputTypeAInputTypeA determines OutputTypeB n input types can drive an output, but currently the maximum number is 3. n输入类型可以驱动一个 output,但目前最大数量为 3。

  1. What is the best way to store the input values?存储输入值的最佳方法是什么? I am considering either:我正在考虑:
  • Storing in one table, with a InputType table FK'd to determine the type of the input value (they will all be strings from a db type perspective).存储在一个表中,使用InputType表 FK 来确定输入值的类型(从 db 类型的角度来看,它们都是字符串)。
  • Storing each input type in a seperate table.将每种输入类型存储在单独的表中。
  1. How can I represent the relationships?我如何代表这些关系? I could have a separate table for each relationship, but this system should be as flexible as possible.我可以为每个关系创建一个单独的表,但这个系统应该尽可能灵活。 I'm concerned that will be a large number of tables, and make it difficult to add new rules.我担心会出现大量表,并且难以添加新规则。

I would think of this as 3 major concepts.我认为这是三个主要概念。

Condition : what needs to be true for a rule to fire?条件:触发规则需要满足什么条件? Rule : when a rule fires, which results are true?规则:当规则触发时,哪些结果是正确的? Result : which outputs fire, and with which values?结果:哪个输出火,以及哪些值?

Conditions are modelled as one or more inputs with their values (your example uses InputTypeA + InputTypeB so I assume a rule has one or more qualifying inputs).条件被建模为一个或多个输入及其值(您的示例使用 InputTypeA + InputTypeB 所以我假设一个规则有一个或多个合格输入)。

Results are modelled as one or more output, with their values.结果建模为一个或多个 output 及其值。

Specifically:具体来说:

Condition
-----------
ID
RuleID
InputType
InputValue

Rule
----
ID

Result
-------
ID
RuleID
OutputType
OutputValue

If there is more logic to input types and output types, you can create a lookup table with a foreign key relationship.如果输入类型和 output 类型有更多逻辑,您可以创建具有外键关系的查找表。

Example might be:示例可能是:

Condition健康)状况

ID RuleID InputType         InputValue
1       1 DrivingIn30zone            1
2       1 CurrentSpeed              40

Rule

ID   Name
1    Don't break the speed limit

Result
ID    RuleID    OutputType    OutputValue
1.         1     SetSpeed              29

You would then search for conditions which match your current input values to see what the output states are:然后,您将搜索与当前输入值匹配的条件,以查看 output 状态是什么:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在数据库中表示“重复事件”的最佳方法是什么? - What is the best way to represent “Recurring Events” in database? 表示在关系数据库中的排序 - Represent Ordering in a Relational Database 以我可用于关系 SQL 数据库的方式访问和组织此不均匀列表列表的最佳方法是什么? - What is the best way to access and organize this list of uneven lists in a way that I could use for a relational SQL database? 在mysql中关系数据库表的最佳实践是什么? - What is the best practise for relational database tables in mysql? 在SQL数据库中表示颜色的最佳方法? - Best way to represent a color in a SQL Database? 在关系数据库中存储事件发生的星期几的最佳方法是什么? - What's the best way to store the days of the week an event takes place on in a relational database? 在关系数据库中存储(和访问)历史1:M关系的最佳方法是什么? - What's the best way to store (and access) historical 1:M relationships in a relational database? 在关系数据库中存储“元数据”的正确方法是什么? - What is the proper way to store 'metadata' in relational database? 将数据插入关系数据库的最简单方法是什么? - What is the easiest way to insert data into a relational database? 在关系数据库中存储未知大小的矩阵的最佳方法? - Best way to store matrix of unknown size in relational database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM