-- 先更改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语句里,连B表都没有,不报错就怪了。
update A set A.address_id = (select B.addressname from B where B.address_id = A.address_id)
执行之前,确认A表address_id字段的类型和长度。
update a set a.address_id = b.addressname where a.address_id=b.addree_id
执行语句前最好检查a.address_id 的长度是否和b.addressname一致,最好大于等于后者,这样转换后信息不丢失。
另外,要求a.address_id为字符型。
update A表 set A表.address_Id=B表.addressname from B表 where A表.address_ID=B表.address_Id
--查询时翻译字段
select A.address_ID,B.addressname from A,B where A.address_ID = B.address_ID
go
--真正update表A
alter table A alter column address_ID varchar(128)
update A set A.address_id = B.addressname where A.address_id=B.addree_id