开发者

How to update value for all rows in table A should update all corresponding column values in table b and c

I need to update a column x with different value for each record in a table of 60 records, and when I update this column in table A ,the column value for this particular column x must also be updated in table b and table c with column x value. Here column x is primary key in table b and c but not in开发者_运维知识库 table a.


This is what triggers are for.

An example taken from the documentation:

mysql> CREATE TABLE account (acct_num INT, amount DECIMAL(10,2));
Query OK, 0 rows affected (0.03 sec)

mysql> CREATE TRIGGER ins_sum BEFORE INSERT ON account
    -> FOR EACH ROW SET @sum = @sum + NEW.amount;
Query OK, 0 rows affected (0.06 sec)

This example does not modify a second table, but that can be done with triggers as well--possibly using a stored procedure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜