CREATE TABLE hoge1 (
.....
id INT(10) UNSIGNED NOT NULL,
count INT(10) UNSIGNED NOT NULL,
hoge_type TINYINT(3) UNSIGNED NOT NULL,
PRIMARY KEY(`id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE hoge2 (
id INT(10) UNSIGNED NOT NULL,
tr_count INT(10) UNSIGNED NOT NULL,
tr_type TINYINT(3) UNSIGNED NOT NULL,
PRIMARY KEY(`id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
DELIMITER $$
CREATE TRIGGER hoge1_insert_sync_hoge2 AFTER INSERT ON hoge1
FOR EACH ROW
BEGIN
INSERT INTO hoge2 (id, tr_count, tr_type) VALUES (NEW.id, NEW.count, NEW.hoge_type);
END;
$$
DELIMITER;
转载请注明:谷谷点程序 » mysql trigger的使用关联插入数据