当前位置: 代码迷 >> Sql Server >> 雪地里跪求一条SQL
  详细解决方案

雪地里跪求一条SQL

热度:41   发布时间:2016-04-27 11:59:27.0
雪地里跪求一条SQL,在线等

有表:A 字段有:(aid,aname,arole)

  B 字段有:(bid, bname)

将数据插入到A中时,aid字段对应的是bid的值

不要这样的写法:insert into A(aid) select bid from B 因为A表字段都是非空的

求条SQL,在线等,新增?

------解决方案--------------------
SQL code
update  aset  aid=b.bidfrom  a join bon  a.aid=b.bid
------解决方案--------------------
SQL code
--仅以aid为例insert into a(aid)select bidfrom bwhere not exists (select 1 from a where a.aid = b.bid)--其他两个字段楼主看情况加,或者和相应表做关联添加吧!
  相关解决方案