Sql server 2008 使用其他表数据更新表数据
我有两张像这样的桌子 tbl_图像:Sql server 2008 使用其他表数据更新表数据,sql-server-2008,Sql Server 2008,我有两张像这样的桌子 tbl_图像: Serial | Src | Albumid ________|__________________|________ 1 | /root/wewe.jpg | 20 2 | /root/wewe.jpg | 21 3 | /root/wewe.jpg | 21 4 | /root/wewe.jpg | 23 5 | /root/w
Serial | Src | Albumid
________|__________________|________
1 | /root/wewe.jpg | 20
2 | /root/wewe.jpg | 21
3 | /root/wewe.jpg | 21
4 | /root/wewe.jpg | 23
5 | /root/wewe.jpg | 18
tbl_专辑:
Albumid | Albumname | AlbumCover
________|__________________|________
20 | AAA | null
21 | bbb | null
31 | vcc | null
42 | ddd | null
18 | eee | null
我要做的是使用第一个表中的SerialNo更改tbl_Album中的AlbumCover值
像
我不擅长复杂查询中的sql…请有人帮帮我 可能是这样的:
Update tbl_Album AS album
set album.AlbumCover=image.Serial
FROM tbl_Album as album
JOIN tbl_image AS image
ON image.Albumid = album.Albumid
您需要
在Albumid
上连接两个表。在过去,我还发现“很难”记住将FROM
-子句放在哪里(在集合
后面):
外键能在这个场景中帮助我吗??
Update tbl_Album AS album
set album.AlbumCover=image.Serial
FROM tbl_Album as album
JOIN tbl_image AS image
ON image.Albumid = album.Albumid
UPDATE a SET a.AlbumCover = i.Serial
FROM tbl_Album a INNER JOIN tbl_image i
ON a.Albumid = i.Albumid