SQLite3数据库中的派生字段 [英] A Derived Field in an SQLite3 Database
问题描述
晚上好每个人,
今天我想问一个关于SQLite3中派生字段(也称为计算字段)的问题。
Today I would like to ask a question relating to derived fields (also known as calculation fields) in SQLite3.
利用存储在我的数据库weight和distance中的两个值,我知道可以利用它们来执行计算,以使用需要两者的公式返回我想要的值。
Utilizing two values stored within my database "weight" and "distance" I know it is possible to utilize them to perform calculations to return the value I want utilizing a formula that requires both.
然而,我想知道是否有一种方法通过SQLite编码设置一个字段,以自动生成自己的值,所以一旦他们输入了重量和距离,计算是
However I am wondering if there is a way to set a field, by SQLite coding, to automatically generate its own value, so once they have entered there weight and distance and the calculation is performed the attribute field for "calories Burned" will then be populated.
或者,我在几个网站上阅读过派生字段,对于3NF数据库,不应该存储在数据库由于3NF的要求,如果是这样,我将不得不继续执行选择计算,当我想要检索的值。
Alternatively I have read on several websites that derived fields, for a 3NF database, should not be stored within the database due to the 3NF requirements, if so I will have to keep performing the select calculation when ever I wish to retrieve the value.
感谢
JHB92
推荐答案
您可以使用 VIEW
:
CREATE VIEW MyTablePlus (Weight, Distance, CaloriesBurned) AS
SELECT Weight, Distance, ((Weight / Distance) * SomeNumber)
FROM MyTable
MyTablePlus
上的 SELECT
语句和您的 INSERT
和 UPDATE
在 MyTable
上的语句。
Now, you can performs your SELECT
statements on MyTablePlus
and your INSERT
and UPDATE
statements on MyTable
.
这篇关于SQLite3数据库中的派生字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!