如果记录不存在,则触发执行插入,否则执行更新 [英] Trigger to perform an insert if record doesn’t exists else perform an update

查看:104
本文介绍了如果记录不存在,则触发执行插入,否则执行更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个表A(selfid作为主键),表B,表C.



如果我更新表A中的列值,触发器应该在表B和表C上执行检查操作。



如果表中存在selfid,则它应该只更新表(B,C)中的列值。 />


如果表中不存在selfid,那么它应该对表(B,C)执行插入操作。

I have three Table A (selfid as primary key) , Table B, Table C.

If I update a column value in Table A , the trigger should perform an check operation on Table B and Table C.

If selfid exists in tables then it should only update the column value in tables(B,C).

If selfid doesn’t exists in tables then it should perform an insert operation on tables(B,C).

推荐答案

如果你有一个像这样的条件列表,触发器是一个不好的选择,因为它们不能很好地扩展。请改用存储过程并让代码调用它。存储过程可以处理所有这些并且无需锁定表以便在另一个请求上执行任何其他操作。
If you've got a list of conditions like this, a trigger is a bad option as they don't scale well. Use a stored procedure instead and have your code call that. The stored procedure can handle all of this and do it without locking the table for any other operation on another request.


这篇关于如果记录不存在,则触发执行插入,否则执行更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆