Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2008 使用其他表数据更新表数据_Sql Server 2008 - Fatal编程技术网

Sql server 2008 使用其他表数据更新表数据

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

我有两张像这样的桌子

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/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