ITPub博客

首页 > 数据库 > SQL Server > SQL Server中快速生成大量记录的SQL脚本

SQL Server中快速生成大量记录的SQL脚本

原创 SQL Server 作者:lawzjf 时间:2008-01-20 12:13:57 0 删除 编辑

下面脚本快速生成1百万条记录的表:

set nocount on
use law
go

if object_id('dbo.nums') is not null
drop table dbo.nums
go

create table dbo.nums(n int not null primary key) on newFG
declare @max as int, @rc as int;
set @max=1000000
set @rc=1

insert into nums values(1)
while @rc*2<=@max
begin
insert into dbo.nums select n+@rc from dbo.nums
set @rc=@rc*2
end

insert into dbo.nums
select n+@rc from dbo.nums where n+@rc<=@max

select count(*) from dbo.nums

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/37724/viewspace-997822/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-01-18

  • 博文量
    279
  • 访问量
    990834