Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Duplicate
-
10.2.44
-
None
-
Not for Release Notes
Description
1.create table
create table person |
(
|
id bigint unsigned not null auto_increment primary key, |
sno varchar(50) not null, |
update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
);
|
|
|
create table person_id123 like person; |
2.create trigger
delimiter $$
|
CREATE TRIGGER school.person_AI_oak AFTER INSERT ON school.person |
FOR EACH ROW |
REPLACE INTO school.person_id123 (`id`, `sno`, `update_time`) VALUES (NEW.`id`, NEW.`sno`, NEW.`update_time`) $$ |
delimiter ;
|
|
|
delimiter $$
|
CREATE TRIGGER school.person_AD_oak AFTER DELETE ON school.person |
FOR EACH ROW |
DELETE FROM school.person_id123 WHERE (id) = (OLD.id) $$ |
delimiter ;
|
|
|
delimiter $$
|
CREATE TRIGGER school.person_AU_oak AFTER UPDATE ON school.person |
FOR EACH ROW |
BEGIN
|
INSERT IGNORE INTO school.person_id123 (`id`, `sno`, `update_time`) VALUES (OLD.`id`, OLD.`sno`, OLD.`update_time`) ; |
UPDATE school.person_id123 SET `id`=NEW.`id`, `sno`=NEW.`sno`, `update_time`=NEW.`update_time` WHERE (id) = (OLD.id) ; |
END $$ |
delimiter ;
|
3.insert data
insert into person(sno) values(100),(200); |
select * from person;
|
--------------------------
|
id sno update_time
|
--------------------------
|
3 100 2025-12-08 18:47:14
|
4 200 2025-12-08 18:47:14
|
--------------------------
|
2 rows in set (0.00 sec)
|
|
|
select * from person_id123 ;
|
--------------------------
|
id sno update_time
|
--------------------------
|
3 100 2025-12-08 18:47:14
|
4 200 2025-12-08 18:47:14
|
--------------------------
|
2 rows in set (0.00 sec)
|
4.update data
update person set sno='100' where id=3;
|
Query OK, 0 rows affected (0.00 sec)
|
Rows matched: 1 Changed: 0 Warnings: 0
|
|
|
select * from person;
|
--------------------------
|
id sno update_time
|
--------------------------
|
3 100 2025-12-08 18:47:14
|
4 200 2025-12-08 18:47:14
|
--------------------------
|
2 rows in set (0.00 sec)
|
|
|
select * from person_id123 ;
|
--------------------------
|
id sno update_time
|
--------------------------
|
|
|
3 100 2025-12-08 18:47:58 #time is updated, I don't want to update.
|
4 200 2025-12-08 18:47:14
|
--------------------------
|
2 rows in set (0.00 sec)
|
If update table `person` 0 row affected , I wish trigger table `person_id123` update_time remain unchanged.
I test in mariadb10.2.22, it's true, but higher than this version update_time is changed.
Could you help me? Thanks
Attachments
Issue Links
- duplicates
-
MDEV-21287 AFTER UPDATE trigger and ON UPDATE now(): new value <> persisted value
-
- Stalled
-