SQL Server 2000是否等效于ON DUPLICATE KEY? [英] SQL Server 2000 equivalent for ON DUPLICATE KEY?

查看:109
本文介绍了SQL Server 2000是否等效于ON DUPLICATE KEY?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在与MySQL的ON DUPLICAT KEY子句等效的SQL Server 2000功能? 此答案使我看了一下在代替触发器"结构中,但该示例看起来很笨拙,并且该功能将隐藏在触发器中,而不是直接在存储的proc中.

Is there a SQL Server 2000 functional equivalent to MySQL's ON DUPLICAT KEY clause? This Answer led me to look at the Instead of Trigger construct, but the sample looks clunky, and the functionality would be hidden in the trigger, and not be directly in the stored proc.

FWIW:我正在尝试为每分钟摘要创建一个统计信息表,这样我就可以调用一个过程来记录操作发生的事实并在适当的分钟内增加计数器.

FWIW: I am trying to create a stats table for per-minute summaries, so that I can just call one Procedure to log the fact that an action happened and increment the counter for the appropriate minute.

推荐答案

我使用这个:

begin tran;

update ... where ... ;

if @@rowcount = 0
  insert ...
commit tran;

据我了解,在适当的索引位置,更新会放置适当的范围锁,以防止其他人同时插入相同的内容.

As I understand it, with proper indices in place, the update places proper range locks that would prevent others from inserting same thing concurrently.

这篇关于SQL Server 2000是否等效于ON DUPLICATE KEY?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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