只用SQL语句,如何向数据库中手工插入十万或一百万条记录!

wtoeb 2009-09-10 01:15:53
只用SQL语句,如何向数据库中手工插入十万或一百万条记录!
...全文
770 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
lyj123net 2011-12-06
  • 打赏
  • 举报
回复
fghgfhfghfgh
fengxianglei 2009-09-11
  • 打赏
  • 举报
回复
alter database 数据库名 set recovery BULK_LOGGED
go

insert into 表名
select id=a.id+b.id+c.id+d.id +e.id +f.id
from(
select id=0 union all select 1
union all select id=2 union all select 3
union all select id=4 union all select 5
union all select id=6 union all select 7
union all select id=8 union all select 9
) a,(
select id=0 union all select 10
union all select id=20 union all select 30
union all select id=40 union all select 50
union all select id=60 union all select 70
union all select id=80 union all select 90
) b,(
select id=0 union all select 100
union all select id=200 union all select 300
union all select id=400 union all select 500
union all select id=600 union all select 700
union all select id=800 union all select 900
) c,(
select id=0 union all select 1000
union all select id=2000 union all select 3000
union all select id=4000 union all select 5000
union all select id=6000 union all select 7000
union all select id=8000 union all select 9000
) d,(
select id=0 union all select 10000
union all select id=20000 union all select 30000
union all select id=40000 union all select 50000
union all select id=60000 union all select 70000
union all select id=80000 union all select 90000
) e,(
select id=0 union all select 100000
union all select id=200000 union all select 300000
union all select id=400000 union all select 500000
union all select id=600000 union all select 700000
union all select id=800000 union all select 900000
)f

go

alter database 数据库名 set recovery full

一百万数据,10秒之内
twfx7758 2009-09-11
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 jinjazz 的回复:]
SQL codeinsertinto tbl(title,datetimes) value('test'+getdate,getdate())go10000
[/Quote]
  • 打赏
  • 举报
回复
用循环插入数据
alicus 2009-09-11
  • 打赏
  • 举报
回复
1000000 是什么意思?插入100w条?
talenter 2009-09-11
  • 打赏
  • 举报
回复
while 或者insert into union all

qiqi860819 2009-09-11
  • 打赏
  • 举报
回复
while 循环
不若倾初 2009-09-10
  • 打赏
  • 举报
回复
100万什么样的数据啊
vipper23 2009-09-10
  • 打赏
  • 举报
回复
insert into tb select SUBSTRING( CONVERT(varchar(100),NEWID()),1,7)
go 1000000
7761098 2009-09-10
  • 打赏
  • 举报
回复

select cast('0000000200000' as decimal(18,2))
create table tbl(
title varchar(100),
datetimes varchar(100)
)
insert into tbl(title,datetimes) select 'test' + CONVERT(varchar(100), GETDATE(), 112),getdate()
go 10000


select * from tbl
xuexuebj 2009-09-10
  • 打赏
  • 举报
回复
我想应该是不规则数据,试想谁会往数据库里插10万条相同的数据
琥珀明月 2009-09-10
  • 打赏
  • 举报
回复
如果单纯的是有规律的数字,用While可以实现,但是不知道具体是什么数据~
华夏小卒 2009-09-10
  • 打赏
  • 举报
回复

declare @i int
set @i=100000
while @i>0
begin
insert into tbl(title,datetimes) value('test' + convert(varchar(20),getdate()),getdate())
set @i=@i-1
end

jinjazz 2009-09-10
  • 打赏
  • 举报
回复
insert into tbl(title,datetimes) value('test' + getdate,getdate())
go 10000
华夏小卒 2009-09-10
  • 打赏
  • 举报
回复
借水哥的结构
子陌红尘 2009-09-10
  • 打赏
  • 举报
回复
declare @i int
set @i=1
while @i<1000000
begin
insert into tbl(title,datetimes) value('test' + convert(varchar(21),getdate(),120),getdate())
set @i=@i+1
end
go
华夏小卒 2009-09-10
  • 打赏
  • 举报
回复

declare @i int
set @i=100000
while @i>0
begin
insert into tbl(title,datetimes) value('test' + getdate,getdate())
set @i=@i-1
end

水族杰纶 2009-09-10
  • 打赏
  • 举报
回复
declare @i int 
set @i=100000
while @i>0
begin
insert into tbl(title,datetimes) values('test',dateadd(mi,@i,getdate()))
set @i=@i-1
end
wtoeb 2009-09-10
  • 打赏
  • 举报
回复
是的,就是添加十万或一百万条记录:
insert into tbl(title,datetimes) value('test' + getdate,getdate())
--小F-- 2009-09-10
  • 打赏
  • 举报
回复
???不是很明白意思
加载更多回复(3)

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧