码迷,mamicode.com
首页 > 数据库 > 详细

sql生成1000W数据

时间:2014-11-27 10:51:19      阅读:334      评论:0      收藏:0      [点我收藏+]

标签:t-sql   100w数据   生成   

declare @d datetime
set @d=getdate()
select * from dbo.ChunkSegmentMapping
select [语句执行花费时间(毫秒)]=datediff(ms,@d,getdate())

USE tempdb
GO
CREATE TABLE tb(id char(8))
CREATE UNIQUE INDEX IX_tb ON tb(id)
WITH IGNORE_DUP_KEY  -- --忽略重复记录的索引
GO
DECLARE @dt datetime
SET @dt = GETDATE()
SET NOCOUNT OFF
DECLARE @row int
SET @row = 1000000 --记录总数为W
WHILE @row >0
BEGIN
 RAISERROR('need %d rows', 10, 1, @row) WITH NOWAIT
 SET ROWCOUNT @row
 INSERT tb SELECT
 id = RIGHT(100000000 + CONVERT(bigint, ABS(CHECKSUM(NEWID()))), 8)
 --FROM syscolumns c1, syscolumns c2  -- SET NOCOUNT ON 49 Second
 FROM syscolumns c1, sysobjects o -- SET NOCOUNT ON 47 Second
 SET @row = @row - @@ROWCOUNT  --设置下次循环需要插入的记录数量
END
SELECT BeginDate = @dt, EndDate = GETDATE(), Second = DATEDIFF(Second, @dt, GETDATE())
GO
SELECT COUNT(*) FROM tb
GO
SELECT * FROM tb
DROP TABLE tb

sql生成1000W数据

标签:t-sql   100w数据   生成   

原文地址:http://blog.csdn.net/mssql_dba/article/details/41541563

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!