两个表的update语句出错

jiangeb 2008-07-29 01:10:05
有两个表,结构如下

T1
**************************
id | country | continent
**************************

T2
*******************************
id | country | continent| recid
*******************************

现在情况是:T2中的recid 分别对应于T1中的id。后者是sql server中的标识类型,前者是不是。
我的目的是根据recid 和id的对应情况,把T2中的country 和 continent 更新到T1中。我的写法如下:
update T1 set T1.country=T2.country,T1.continent=T2.continent where T1.id=T2.recid
在查询分析器中运行,错误提示为:
服务器: 消息 107,级别 16,状态 3,行 1
列前缀 'istp080729country' 与查询中所用的表名或别名不匹配。
请问是什么意思? 应该怎么修改,谢谢!

...全文
74 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
utpcb 2008-07-29
  • 打赏
  • 举报
回复
update T1 set T1.country=T2.country,T1.continent=T2.continent 
FROM T1 ,T2
where T1.id=T2.recid


其实和select 一样 只是吧select 换成update set就可以了
rhq12345 2008-07-29
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hery2002 的回复:]
SQL codeupdate T1 set T1.country=T2.country,T1.continent=T2.continent
FROM T1 ,T2
where T1.id=T2.recid
[/Quote]
rockyvan 2008-07-29
  • 打赏
  • 举报
回复
[Quote=引用楼主 jiangeb 的帖子:]
在查询分析器中运行,错误提示为:
服务器: 消息 107,级别 16,状态 3,行 1
列前缀 'istp080729country' 与查询中所用的表名或别名不匹配。
[/Quote]
[Quote=引用 3 楼 hery2002 的回复:]
多表关联更新,需要指定FROM关键字,
[/Quote]
如果指定了,確保沒有指錯!
pt1314917 2008-07-29
  • 打赏
  • 举报
回复

update T1 set country=T2.country,continent=T2.continent from t1,t2 where T1.id=T2.recid

jhwcd 2008-07-29
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hery2002 的回复:]
SQL codeupdate T1 set T1.country=T2.country,T1.continent=T2.continent
FROM T1 ,T2
where T1.id=T2.recid
[/Quote]
用1楼方法就行了。
yrwx001 2008-07-29
  • 打赏
  • 举报
回复
..
hery2002 2008-07-29
  • 打赏
  • 举报
回复
多表关联更新,需要指定FROM关键字,
yrwx001 2008-07-29
  • 打赏
  • 举报
回复
update T1 set T1.country=T2.country,T1.continent=T2.continent from T1,T2 where T1.id=T2.recid 
hery2002 2008-07-29
  • 打赏
  • 举报
回复
update T1 set T1.country=T2.country,T1.continent=T2.continent 
FROM T1 ,T2
where T1.id=T2.recid

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧