【发布时间】:2014-08-20 17:47:40
【问题描述】:
当将行插入tablea 时,如何使用tablea 中的值自动更新第二个表tableb,而不需要任何存储过程或其他东西。
例如,如果要在此处将一行插入 tablea,我想用 itemId 中的 tablea 更新 tableb 中的所有行,其中 itemTempId 中的 itemTempId tableb 是相同的作为tablea中的那个
两个表都是 MyIsam 类型
插入表格之前
tablea
"id" "itemId" "itemTempId" "itemName"
- - - -
tableb
"id" "itemId" "itemTempId" "itemImageName"
"1" \N "T001" "front.jpg"
"2" \N "T001" "side-left.jpg"
"3" \N "T001" "side-right.jpg"
"4" \N "T001" "back.jpg"
插入tablea后
tablea
"id" "itemId" "itemTempId" "itemName"
"1" "US01" "T001" "Samsung Galaxy Note 5"
tableb //updated with the itemId from tablea where itemTempId are the same
"id" "itemId" "itemTempId" "itemImageName"
"1" "US01" "T001" "front.jpg"
"2" "US01" "T001" "side-left.jpg"
"3" "US01" "T001" "side-right.jpg"
"4" "US01" "T001" "back.jpg"
【问题讨论】:
-
如果不使用
Trigger,我不知道你怎么能做到。 -
@Norman 你确定即使你不想使用任何触发器或任何 sql?
-
如果表是 INNODB,这可能吗?有外键?
-
@prashantthakre 我目前用 php 和 sql 来做