选择数据,将计算值设置到列中
我正在从触发器内的表中选择数据(用于更新)。我选择的某些行已由启动触发器的事务更新,而某些行则没有。我想在数据集中的某处为每一行写入一个标志,该值将计算为“id IN (SELECT [id] FROM INSERTED)”。该标志将显示一行是否已使用最后一个事务更新。
在SQL中可以吗?
当然,我可以用 2 个不同的条件执行 2 个单独的查询,但触发器性能是真正的瓶颈......
I'm selecting data from a table within a trigger (FOR UPDATE). Some rows I'm selecting have been updated by a transaction, that initiated the trigger, and some rows are not. I'd like to write somewhere in the dataset a flag for every row, which value would be calculated as "id IN (SELECT [id] FROM INSERTED)". This flag would show, is a row updated with the last transaction or not.
Is it possible in SQL?
Sure, I can do 2 separate queries, with 2 different conditions, but the trigger perfomance is real bottleneck...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 SQL Server 的示例:
打印:
Here's an example for SQL Server:
This prints: