当前位置: 代码迷 >> Sql Server >> 怎么将B表的一个字段的数据复制到A表中的一个字段,这个字段名一样的
  详细解决方案

怎么将B表的一个字段的数据复制到A表中的一个字段,这个字段名一样的

热度:14   发布时间:2016-04-27 11:24:34.0
如何将B表的一个字段的数据复制到A表中的一个字段,这个字段名一样的
等待答案。

------解决方案--------------------
给个模型 好写测试代码
------解决方案--------------------
SQL code
--新建#aselect *into #afrom (select 1 a ,'a' b union allselect 2 ,'b' union allselect 3 ,'c' union allselect 4 ,'d' )a--新建#bselect *into #bfrom (select 5 a ,'a' b union allselect 6 ,'b' union allselect 7 ,'c' union allselect 8 ,'d' )a--查询#aselect * from #a--result:a           b----------- ----1           a2           b3           c4           d(4 行受影响)--查询#bselect * from #b--result:a           b----------- ----5           a6           b7           c8           d(4 行受影响)--插入#a中a字段insert into #a select a,'' b from #b(4 行受影响)--查询表#aselect * from #a--result:a           b----------- ----5           6           7           8           1           a2           b3           c4           d(8 行受影响)
------解决方案--------------------
insert b (column1) select column1 from a
------解决方案--------------------
SQL code
INSERT INTO TB_A(COLUMN_NAME)SELECT COLUMN_NAME FROM TB_B
  相关解决方案