A表 B表
A表、B表都有address_ID这一列,B表中的addressname是address_ID对应的具体内容。请问,如何将A表中的address_ID改为B表中对应的addressname?
1楼、2楼你们的回答确定是sql sever上的语句吗??
-- 先更改A表中列的数据类型
ALTER TABLE A ALTER COLUMN address_ID VARCHAR(128)
-- 开始联接查询,条件更新
UPDATE a
SET a.address_ID = b.addressname
FROM a, b
WHERE a.address_ID = b.address_ID
SELECT * FROM a
update A set A.address_id = B.addressname where A.address_id=B.address_id
为什么报错啊
能留个联系方式吗 详谈~~
不好意思,没验证。现在把经过验证的给你。在sql2000,2005,2008上通过
UPDATE a
SET address_id = c.addressname
FROM a INNER JOIN
(SELECT address_id, addressname
FROM b) AS c ON a.address_id = c.address_id
绝对不报错。
注意a表address_id 为字符型,且宽度足够
update A set A.address_id = B.addressname where A.address_id=B.address_id
为什么报错啊
能留个联系方式吗 ? 详谈~~
我晕,纯属失误,这句应该没问题了
update a set a.address_ID = b.addressname from a,b where a.address_ID = b.address_ID