将一张巨大的桌子拆分成小桌子

时间:2017-09-12 09:52:36

标签: sql-server tsql

我在Microsoft SQL Server 2008 R2中有一个表,它有100,000条记录。

我需要将它拆分为10个表,每个表有10k个记录。我不想对表进行分区,而是将其完全拆分为10个不同的表。这可能吗?

2 个答案:

答案 0 :(得分:1)

你可以使用NTile

;with cte
as
(
select ntile(10) over (order by somepk column) as somecol
,* from table 
)
select * from cte where n=1--change n value to get each partition

答案 1 :(得分:0)

SELECT * 
 INTO new_tb1 
 FROM old_tb
 WHERE row >= 1 AND row<= 10000;

SELECT * 
 INTO new_tb2 
 FROM old_tb
 WHERE row>= 10001 AND row<= 20000;

.
.
.
.
.
SELECT * 
 INTO new_tb3 
 FROM old_tb
 WHERE row>= 90001 AND row<= 100000;