sql生成1000W数据

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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。