I am using MYSQL 5.1.38 and I have following tables:
create table table1 (
col1 varchar(50) primary key not null,
ts1 timestamp not null default current_timestamp on update current_timestamp
)engine=innodb;
create table table2 (
col1 varchar(50) not null,
ts2 timestamp not null default current_timestamp on update current_timestamp,
foreign key (col1) references table1 (col1) on update cascade on delete cascade
)engine=innodb;
When I update col1 in table1, the ts1 in table1 and col1 in table2 are updated but ts2 in table2 does not get updated.
Here is the output:
mysql> insert into table1 (col1) values ('test'); Query OK, 1 row affected (0.00 sec) mysql> insert into table2 (col1) values ('test'); Query OK, 1 row affected (0.00 sec) mysql> select * from table1; +------+---------------------+ | col1 | ts1 | +------+---------------------+ | test | 2013-05-17 09:37:56 | +------+---------------------+ 1 row in set (0.00 sec) mysql> select * from table2; +------+---------------------+ | col1 | ts2 | +------+---------------------+ | test | 2013-05-17 09:38:03 | +------+---------------------+ 1 row in set (0.01 sec) mysql> update table1 set col1='test1' where col1 = 'test'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from table1; +-------+---------------------+ | col1 | ts1 | +-------+---------------------+ | test1 | 2013-05-17 09:44:28 | +-------+---------------------+ 1 row in set (0.00 sec) mysql> select * from table2; +-------+---------------------+ | col1 | ts2 | +-------+---------------------+ | test1 | 2013-05-17 09:38:03 | +-------+---------------------+ 1 row in set (0.00 sec)
I would expect ts2 to be updated as well. Is this expected behaviour?