新建表c1CREATE TABLE c1 (
id int(11) NOT NULL auto_increment PRIMARY KEY,
kl VARCHAR(255)
)
向表c1插入数据INSERT INTO
c1(kl)
VALUES
('李'),('周'),('王'),('赵')
新建表c2CREATE TABLE c2 (
id int(11) NOT NULL auto_increment PRIMARY KEY,
kl VARCHAR(255)
)
向表c2插入数据INSERT INTO
c2(kl)
VALUES
('1'),('1'),('1'),('1')
创建触发器c1表更新后,同样更新c2表create trigger c1_update_c2 after UPDATE
on c1 for each ROW
BEGIN
UPDATE c2 set kl=new.kl where id =(select id from c1 where kl=new.kl);
end
#select id from c1 where kl=new.kl 查询更新的值对应的ID的值是
更新表c1的kl值,查看c2对应的值UPDATE c1
SET kl = '李四'
where id=1;
SELECT * from c1;
SELECT * from c2;