简体   繁体   English

在表行之间实现数据数学一致性

[英]Implementing data mathematical consistency among table rows

I have 3 tables: Persons , Variables , Person_Data . 我有3个表: PersonsVariablesPerson_Data

Person_Data table has numerical data on various variables for different persons. Person_Data表具有有关不同人员的各种变量的数值数据。 Columns are: variable_value , person_id (foreign key to Persons ) and variable_id (fk to Variables ). person_idvariable_valueperson_idPersons外键)和variable_id (fk到Variables )。

Some of the variables are related to each other (for example: Income, Family size and Per-capita-income). 一些变量是相互关联的(例如:收入,家庭规模和人均收入)。 I want to create a Variable_Relationship table to store this type of information and perform data sanity check. 我想创建一个Variable_Relationship表来存储这种类型的信息并执行数据完整性检查。 One of the column in the table would be Dependant_Variable_Id (LHS of the relationship). 该表中的一列将是Dependant_Variable_Id (关系的LHS)。

  1. The issue is that the number of RHS variables is not fixed and neither is the mathematical expression. 问题在于RHS变量的数量不是固定的,数学表达式也不是固定的。
  2. Is there a way to implement this nicely? 有没有办法很好地实现这一目标?

Right now I am thinking about a relationship_definition text column along with another table that has Relationship_Id and RHS_VariableId columns. 现在,我正在考虑一个relationship_definition文本列以及另一个具有Relationship_IdRHS_VariableId列的表。

In my opinion there is no way to manage it in SQL, since you have no way to interpret dynamically formulas expressed in column values. 在我看来,由于无法动态解释以列值表示的公式,因此无法在SQL中进行管理。 Depending on the language you use to access data on the database, you should develop an expression parser (you can search for plenty of open source libraries providing such a feature) and use it to parse the expressions read from the RHS column, evaluate them and perform sanity checks. 根据用于访问数据库数据的语言,您应该开发一个表达式解析器(您可以搜索大量提供此类功能的开源库),然后使用它来解析从RHS列读取的表达式,对其求值并执行健全性检查。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM