惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Blog — PlanetScale
Blog — PlanetScale
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Last Watchdog
The Last Watchdog
AI
AI
Recent Announcements
Recent Announcements
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
J
Java Code Geeks
TaoSecurity Blog
TaoSecurity Blog
L
LangChain Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Project Zero
Project Zero
Microsoft Security Blog
Microsoft Security Blog
量子位
T
Threatpost
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园 - Franky
博客园 - 聂微东
L
LINUX DO - 最新话题
Security Archives - TechRepublic
Security Archives - TechRepublic
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
C
Check Point Blog
宝玉的分享
宝玉的分享
G
Google Developers Blog
Spread Privacy
Spread Privacy
Cloudbric
Cloudbric
SecWiki News
SecWiki News
有赞技术团队
有赞技术团队
www.infosecurity-magazine.com
www.infosecurity-magazine.com
W
WeLiveSecurity
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
美团技术团队
V
Vulnerabilities – Threatpost
Cyberwarzone
Cyberwarzone
A
Arctic Wolf
P
Privacy & Cybersecurity Law Blog
P
Palo Alto Networks Blog
H
Help Net Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
A
About on SuperTechFans
N
Netflix TechBlog - Medium
罗磊的独立博客
月光博客
月光博客

博客园 - KK2038

诚招.Net研发人员 VS编译时自动引用Debug|Release版本的dll 盘点国内外不同特色的Web流量分析工具 IE无法设置短域名下Cookie 使用XamlReader.Load构建配置型自定义控件 Java/Js如何使用正则表达式匹配嵌套Html标签 几个有趣的Javascript Hack Hilo: Windows 7下C++应用程序开发实战演练 晒晒自己电脑里的常用工具 Visual Studio编辑器一次缩进/反缩进4个空格 Win7访问远程桌面最大化同时让任务栏可见 关于字符编码,你所需要知道的 Silverlight 4+RIA Services--搜索引擎优化(SEO) 64位系统下IIS7 ISAPI处理器加载失败 为什么IIS7/7.5的Gzip不起作用 SSIS调用存储过程失败 当Google Analytics、Firefox和IIS走到了一起... VS2010的UI设计失误 微软技术社区精英计划——你也来加入吧
Sql Tips——Update语句也使用表别名(Table Alias)
KK2038 · 2010-07-09 · via 博客园 - KK2038

在编写Sql脚本时通过表别名可以大大缩减Sql代码,同时表别名也是解决同表多次引用的手段之一。在select中使用表别名大家应该都很熟悉了:

select * from TableA as A inner join TableB as B on A.Key1 = B.Key1

但是在Update中使用表别名可能就没那么多人知道了。

update T
set T.Key1 = 'xxxx'
from TableA T

这些天在写Sql Update脚本的时候需要引用两次同个表对象,如果直接像下面这样引用两次TableA则会抛出“The multi-part identifier ‘TableA.Index’ could not be bound”的错误。这是因为Sql引擎无法知道你在where子句中的TableA到底指的是要Update的表还是from后面的表。

update TableA
set TableA.NextKey = T.Key
from TableA T
where T.Index = TableA.Index + 1

如果不对Update后面的TableA使用别名的话,我们只能通过以下方法来实现。

update TableA
set TableA.NextKey = T.Key
from 
(
  select * from TableA
)T
where T.Index = TableA.Index + 1

使用别名可以得到更简洁的写法:

update T1
set T1.NextKey = T2.Key
from TableA T1, TableA T2
whereT2.Index = T1.Index + 1

——Kevin Yang