add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE test (
id INT AUTO_INCREMENT PRIMARY KEY,
val INT
);
CREATE TRIGGER tr_ins -- save id of the inserted row
AFTER INSERT ON test
FOR EACH ROW
SET @inserted := CONCAT_WS(',', @inserted, NEW.id);
CREATE TRIGGER tr_upd -- save id of the updated row
AFTER UPDATE ON test
FOR EACH ROW
SET @updated := CONCAT_WS(',', @updated, NEW.id);
-- clear user-defined variables which will collect the list of effected rows
SET @inserted := NULL;
SET @updated := NULL;
INSERT INTO test VALUES
(1,1), -- explicit insert
(NULL,2), -- autogenerated insert
(NULL,3), -- autogenerated insert
(2,4), -- update
(1,5), -- update
(2,6), -- update
(NULL,7), -- autogenerated insert
(5,8), -- explicit insert
(3,9) -- update
ON DUPLICATE KEY UPDATE val = VALUES(val);
SELECT * FROM test;
-- see the lists of inserted/updated row's id values
SELECT @inserted, @updated;
Records: 9  Duplicates: 4  Warnings: 1
id val
1 5
2 6
3 9
4 7
5 8
@inserted @updated
1,2,3,4,5 2,1,2,3