[英]Implementing data mathematical consistency among table rows
I have 3 tables: Persons
, Variables
, Person_Data
. 我有3个表:
Persons
, Variables
, Person_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_id
: variable_value
, person_id
( Persons
外键)和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)。
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_Id
和RHS_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.