How to create sql constraints in my table
问题 i have this table: id | product_group_id | percentage 1 | 1 | 0.2 2 | 1 | 0.3 3 | 1 | 0.5 4 | 2 | 0.4 5 | 2 | 0.6 I want to know if there is a way to create constraints that for each product_group_id the percentage will be equal to 1 ( if product_group_id = 1 so 0.2 + 0.3 + 0.5 = 1). For example if i will change the percentage where id = 2 to 0.8 or 0.1, the update (or insert) will fail because the sum is not 1. Thanks in advanced. 回答1: It would generally make more sense to enforce this sort