MYSQL: Sequential Number Table

前端 未结 8 1826
清歌不尽
清歌不尽 2020-12-15 14:33

I am trying to get a sequential number table from 1 to 20 million. (or 0 to 20 million)

I am rather awestruck at how difficult it\'s been to get a MySQL-compatible s

8条回答
  •  不思量自难忘°
    2020-12-15 15:25

    I am not sure if you are trying to make one call make 20 million rows or call a row making call 20 million times. An example of the second case would be:

    
    

    If you are looking for a SQL solution couldn't you try an adaption of

    DROP TABLE NumbersTest
    DECLARE @RunDate datetime
    SET @RunDate=GETDATE()
    SELECT TOP 20000000 IDENTITY(int,1,1) AS Number
        INTO NumbersTest
        FROM sys.objects s1
        CROSS JOIN sys.objects s2
    ALTER TABLE NumbersTest ADD CONSTRAINT PK_NumbersTest PRIMARY KEY CLUSTERED (Number)
    PRINT CONVERT(varchar(20),datediff(ms,@RunDate,GETDATE()))+' milliseconds'
    SELECT COUNT(*) FROM NumbersTest
    

    Taken from this post and is reported to make 10,000 rows in an average of 56.3 milliseconds.

提交回复
热议问题