开始设计一张表的时候,由于该表数据量逐渐增多。达到百万或千万的数据量的时候。
你原来的程序区查询该表。会出现时间很长,有的时候会出现连接池异常。因为大批量并发去查询该表,等待时间长,会占用很多连接资源而没有释放数据库连接,而导致的。
所以我们经常要对该表进行表与表的转移。将A表数据定期转移到B表中。然后查询的时候,从视图中进行查询,视图中可以采用:(A和B是主表和备份表,定期将A表数据同步到B表中)
select * from A
union all
select * from B
转移的时候,用一个任务
select id,name,password
into #temp
from A
insert into B (id,name,password)
select
a,b,c from #temp
delete a from A a,B b where a.id=b.id