如何根据库存表的产品ID字段从产品表获取产品名称等信息更新库存表记录

yzwgh 2005-03-05 04:47:36
库存表有产品ID,产品名称,产品型号等字段,但产品名称,型号等为空,我想根据产品ID从产品表取得相应的名称等记录填入库存表,SQL语句怎么写?相关字段名称如下:
库存表:t_kc(productid,amount,productname,producttype)
产品表:t_product(productid,productname,producttype)
...全文
166 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yzwgh 2005-03-05
  • 打赏
  • 举报
回复
希望有机会能跟大家交个朋友
MSN:wghchina@hotmail.com
QQ:383713072
EMAIL:yzwgh@sina.com
hsj20041004 2005-03-05
  • 打赏
  • 举报
回复
update A
set A.productname=B.productname,A.producttype=B.producttype
from t_kc A inner join t_product B
on A.productid=B.productid
zjcxc 元老 2005-03-05
  • 打赏
  • 举报
回复
--如果你担心出错,可以加事务

begin tran

--更新
update a set productname=b.productname,producttype=b.producttype
from t_kc a,t_product b
where a.productid=b.productid

--显示结果
select * from t_kc

--如果确认无误,手工输入并执行下面的语句提交事务
--commit tran
zjcxc 元老 2005-03-05
  • 打赏
  • 举报
回复
update a set productname=b.productname,producttype=b.producttype
from t_kc a,t_product b
where a.productid=b.productid
yzwgh 2005-03-05
  • 打赏
  • 举报
回复
楼上的,你有没有试过呀,这样拿到库里去执行,弄不好会死人的
fesxe 2005-03-05
  • 打赏
  • 举报
回复
update t_kc set productname=b.productname ,producttype=b.producttype
from t_kc a, t_product b where a.productid=b.productid

34,594

社区成员

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

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