在 Update 语句中使用表别名的好方法? [英] Good way to use table alias in Update statement?

查看:53
本文介绍了在 Update 语句中使用表别名的好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 SqlServer,并尝试更新同一个表中的行.我想使用表别名来提高可读性.这就是我目前的做法:

Using SqlServer, and trying to update rows from within the same table. I want to use a table alias for readability. This is the way I am doing it at the moment:

UPDATE ra 
SET ra.ItemValue = rb.ItemValue
FROM dbo.Rates ra, dbo.Rates rb
WHERE ra.ResourceID = rb.ResourceID
AND ra.PriceSched = 't8'
AND rb.PriceSched = 't9'

有更简单/更好的方法吗?

Are there easier / better ways?

推荐答案

UPDATE ra 
   SET ra.ItemValue = rb.ItemValue
  FROM dbo.Rates ra
 INNER JOIN dbo.Rates rb
         ON ra.ResourceID = rb.ResourceID
WHERE ra.PriceSched = 't8'
  AND rb.PriceSched = 't9';

这可能有助于提高性能.

This might help in improving performance.

这篇关于在 Update 语句中使用表别名的好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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