如何将TBL_PACKAGE
中的值自动插入到TBL_MEMBER
的外键中?
示例:如果我有两个表:
TBL_MEMBER表
+----+-----------+---------------+-----------------+
| ID | USER_NAME | PACKAGE_ID_FK | UPDATE_TIMES_FK |
+----+-----------+---------------+-----------------+
| No data available in table |
+----+-----------+---------------+-----------------+
TBL_PACKAGE
+----+--------------+--------------+
| ID | PACKAGE_NAME | UPDATE_TIMES |
+----+--------------+--------------+
| 1 | FREE | 5 |
| 2 | PREMIUM | 10 |
+----+--------------+--------------+
注册USER1
后USER1
将获得FREE
个包然后PACKAGE_ID_FK
会自动将值插入1
和UPDATE_TIMES_FK
自动插入值为5
。
TBL_MEMBER 应如下所示:
+----+-----------+---------------+-----------------+
| ID | USER_NAME | PACKAGE_ID_FK | UPDATE_TIMES_FK |
+----+-----------+---------------+-----------------+
| 1 | USER1 | 1 | 5 |
+----+-----------+---------------+-----------------+
当注册用户购买PREMIUM
个包时,会自动将PACKAGE_ID_FK
值设置为2
,将UPDATE_TIMES_FK
值设置为10
。
USER1
购买PREMIUM
套餐后TBL_MEMBER 应如下所示:
+----+-----------+---------------+-----------------+
| ID | USER_NAME | PACKAGE_ID_FK | UPDATE_TIMES_FK |
+----+-----------+---------------+-----------------+
| 1 | USER1 | 2 | 10 |
+----+-----------+---------------+-----------------+