现在我是用游标遍历A表
select * from B wher b.Id = @AId
来查询操作,时间是13分钟左右
如果用 select * from B wher b.Id in (select id from A) 插入临时表#B
然后游标遍历A表
select * from #B wher b.Id = @AId
这样来操作 会不会好些?
还是有别的好方法么?
...全文
158711打赏收藏
SQL 循环查询还是用In
A表100条数据 Id、 B表两千万条数据 Id(索引)、根据A表查询B表的数据 现在我是用游标遍历A表 select * from B wher b.Id = @AId 来查询操作,时间是13分钟左右 如果用 select * from B wher b.Id in (select id from A) 插入临时表#B 然后游标遍历A表 select * from #B wher b.Id = @AId 这样来操作 会不会好些? 还是有别的好方法么?
A表一对多B表 把B表的数据插入、修改入C表
set @ t1 =(select val from #B where id=@AId and type='1')
是否存在@ t1 执行 插入C
set @ t2 =(select val from #B where id=@AId and type='2')
是否存在@ t2 执行 插入C
set @ t3 =(select val from #B where id=@AId and type='3')
是否存在@ t3 执行 插入C