求:数据恢复的语句!
t_leaf:
id name time no
1 a ...... 2
2 b ....... 100
2 b ....... 100
2 b ....... 100
t_root:
id name time Total_no
2 b ....... 1000
期望,我在t_leaf中增加一条后,对应t_root中的Total_no会自动减少t_leaf中的no的数字,
同理在t_leaf中删除一条厚,对应t_root中的Total_no会自动增加t_leaf中的no的数字
举例:t_leaf中心赠加
id name time no
1 b ...... 2
那么这时候t_root中应该是
id name time Total_no
2 b ....... 998
举例:t_leaf中心删除一条记录
id name time no
1 b ...... 200
那么这时候t_root中应该是
id name time Total_no
2 b ....... 1198
我的想法是通过trigger来实现,不过sql语句不太熟练,请大家指点一下。