gpt4 book ai didi

mysql - 在mysql中可以在更新某些行时自动执行某种触发器或函数或过程吗?

转载 作者:行者123 更新时间:2023-11-30 22:53:00 27 4
gpt4 key购买 nike

我是数据库的新手。我有这张名为 guide 的表格:


+----------+----------------------+--------------+-------------+
| phone | address | name | cellphone |
+----------+----------------------+--------------+-------------+
| 2555555 | 1020 PANORAMA | JUAN CARLOS | 0999999999 |
| 2555555 | GABRIEL JOSE 1020 | JOSE MIGUEL | 0988888888 |
| 2555555 | C ATARAZANA 1020 | SILVIA | 0777777777 |
| 2555555 | GABRIEL JOSE 1020 | VIOLETA | 0888888888 |
+----------+----------------------+--------------+-------------+

例如,当它获得新添加的行时


+----------+----------------------+--------------+-------------+
| phone | address | name | cellphone |
+----------+----------------------+--------------+-------------+
| 2555555 | 1020 PANORAMA | JUAN CARLOS | 0999999999 |
| 2555555 | FRANCISCO 1520 | JOSE MIGUEL | 0988888888 |
| 2555555 | C ATARAZANA 1020 | SILVIA | 0777777777 |
| 2555555 | GABRIEL JOSE 1020 | VIOLETA | 0888888888 |
| | GABRIEL VILLA 102 | PANCHA | | NEW DATA
+----------+----------------------+--------------+-------------+

它在另一个名为names的表中只添加姓名和手机


+--------------+-------------+
| name | cellphone |
+--------------+-------------+
| JUAN CARLOS | 0999999999 |
| JOSE MIGUEL | 0988888888 |
| SILVIA | 0777777777 |
| VIOLETA | 0888888888 |
| PANCHA | | NEW DATA
+--------------+-------------+

当第一个表中的行更新时,它更新第二个表这可能是什么?

最佳答案

试试这个触发器

`CREATE DEFINER=`root`@`localhost` TRIGGER `dbname`.`guideafterinsert` 
AFTER INSERT ON `guide`
FOR EACH ROW
BEGIN
update phone
set
name = new.name,
cellphone=new.cellphone,
END`

关于mysql - 在mysql中可以在更新某些行时自动执行某种触发器或函数或过程吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27519100/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com