Microsoft SQL Server 在更新中使用联接
示例
连接还可以在UPDATE语句中使用:
CREATE TABLE Users (
UserId int NOT NULL,
AccountId int NOT NULL,
RealName nvarchar(200) NOT NULL
)
CREATE TABLE Preferences (
UserId int NOT NULL,
SomeSetting bit NOT NULL
)SomeSetting通过Preferences表上的谓词更新表过滤的列,Users如下所示:
UPDATE p SETp.SomeSetting= 1 FROM Users u JOIN Preferences p ONu.UserId= p.UserId WHEREu.AccountId= 1234
p是在语句Preferences的FROM子句中定义的别名。仅具有匹配的行AccountId从Users表将被更新。
用左外部联接语句更新
Update t SET t.Column1=100 FROM Table1 t LEFT JOIN Table12 t2 ON t2.ID=t.ID
使用内部联接和聚合功能更新表
UPDATE t1 SET t1.field1 = t2.field2Sum FROM table1 t1 INNER JOIN (select field3, sum(field2) as field2Sum from table2 group by field3) as t2 on t2.field3 = t1.field3
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下