SQL Server数据库怎么用sql语句同时插入一亿条数据?(存储过程也行)

这是面试题,我觉得没这么容易吧
2025-04-28 07:58:38
推荐回答(4个)
回答1:

要想同时插入必须通过线程才能实现 并发,大体代码如下:
public class TestInsert extends Thread{
public void run(){
try {
insert 语句..............
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {

for(int i=0;i<100000;i++){
try {
new TestInsert (). start();
} catch (Exception e) {
e.printStackTrace();
}
}

}

}

回答2:

写个循环 就ok 了

declare @Count int=10000000000---设置你想插入的条数
while @Count>0
begin
insert into users values ('测试',@Count)
set @Count = @Count-1
end

回答3:

写个循环,把要插入的做的循环,或者用批处理

回答4:

create table tb(num int)
insert into tb values(1)
go 100000000