将A表中的数据更新或插入到B表中 id作为关联
来源:互联网 发布:荷塘月色淘宝 编辑:程序博客网 时间:2024/04/30 04:10
--------更新-------
方法一:子查询更新
update B set
name=(select name from A where id=B.id),
sex = (select sex from A where id=B.id)
方法二:游标更新
declare @id int
declare @name nvarchar(50)
declare @sex int
declare cur cursor for
select
id,
name,
sex
from A
open cur
fetch next from cur into
@id,
@name,
@sex
while @@fetch_status=0
begin
update B set
name=@name,
sex=@sex
where id=@id
fetch next from cur into
@id,
@name,
@sex
end
close cur
deallocate cur
方法三:关联更新(效率最优)sql server支持这种写法
update b set
name=a.name,
sex=a.sex
from B as b
inner join A as a on(a.id=b.id)
// mysql支持的语法
UPDATE tablename1,tablename2 SET tablename1.id= tablename2.id
WHERE tablename1.name = tablename2.name;
------插入------
insert into B
(
name,
sex
)
select name,sex from A
- 将A表中的数据更新或插入到B表中 id作为关联
- sql-b表数据插入或更新到a表
- T-SQL - 通过关联ID,将A表中多列ID关联为B表中的数据
- 将表B中的某几列数据更新到表A中
- sql server 将A数据库中a表的数据插入B数据库中的b表
- 将b表中的数据覆盖到a表中的sql(批量更新数据sql)
- SQL中 将同一个表中的A列更新到B列,B列更新到A列
- mysql 将A表数据插入到B表
- MySQL将表a中查询的数据插入到表b中
- 使用A表中的数据插入到B表中(B表已经存在)
- oracle中查询出A表的结果,并将A表中的数据插入到B表中,对于A表中已经存在的B表数据不在插入
- sql 中如何将A表的数据更新到B表中,数据表备份语句
- SQL 将A表三列插入到B表中
- SQl 将A表中的字段Name的值更新到B表中
- 更新 将B表的数据更新到A表中的某个字段的sql(根据条件)
- 查询A表数据插入到B表中
- 插入数据a表到b表
- 将B数据库客户基本信息表中的字段插入到A数据库表中对应的字段中
- 【分享】推荐一些不错的计算机书籍
- java commons-fileupload 上传时的中文乱码问题
- mm_free()
- 浅谈MySQL索引背后的数据结构及算法
- 帝国cmsGroup之后合计(count)总数
- 将A表中的数据更新或插入到B表中 id作为关联
- 老师们都是这样计算毕业设计分数的
- MySQL Binlog (异常) unknown variable 'default-character-set=utf8'
- 关于C语言和汇编语言相互嵌套调用
- MYSQL 主从热备方式配置
- Eclipse快捷键 10个最有用的快捷键
- 自定义ImageView实现图片的单指拖动和两指缩放
- jquery 事件 trigger
- EditText 区别输入中文还是英文