图书(B_ID 为 PK)
| B_ID | Name | Unit_Price|
|------+---------+-----------|
| B01 | Math | 25 |
| B02 | Science | 34 |
订单(O_ID 为 PK)
| O_ID | Date | Total_Price |
|------+---------+-------------|
| O01 | 12/1/16 | NULL |
| O02 | 20/3/16 | NULL |
订单详情(O_ID,B_ID 是复合 PK,其中两个 ID 都是上表的 FK)
| O_ID | B_ID | Quantity |
|------+------+-----------|
| O01 | B01 | 2 |
| O01 | B02 | 1 |
| O02 | B02 | 5 |
如何通过将 NULL 替换为计算结果来将计算插入Total_Price
( Unit_Price
* )。Quantity
我尝试使用 CTE 解决它,但我不喜欢在添加新记录(Exp: O03)时我需要再次运行 CTE 来更新它。