daily pastebin goal
23%
SHARE
TWEET

Untitled

a guest Jan 24th, 2018 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --- 10000000 случайных чисел, за 34 секунд
  2. USE [Sandbox]
  3.  
  4. IF OBJECT_ID (N'dbo.[Random Numbers]', N'U') IS NULL
  5.     CREATE TABLE [dbo].[Random Numbers](
  6.         [RESULT] [INT] NOT NULL
  7.     ) ON [PRIMARY]
  8.  
  9. TRUNCATE TABLE dbo.[Random Numbers];
  10.  
  11. WITH
  12. -- Список простых чисел [0..9]
  13. SimpleDigits AS (
  14.           SELECT 0 AS NUMBER
  15.     UNION SELECT 1
  16.     UNION SELECT 2
  17.     UNION SELECT 3
  18.     UNION SELECT 4
  19.     UNION SELECT 5
  20.     UNION SELECT 6
  21.     UNION SELECT 7
  22.     UNION SELECT 8
  23.     UNION SELECT 9
  24. ),
  25.  
  26. -- Список чисел [0..10000000]
  27. Digits AS (
  28.  
  29. SELECT
  30.       (Millions.NUMBER * 1000000)
  31.     + (HundredThousands.NUMBER * 100000)
  32.     + (TenThousands.NUMBER * 10000)
  33.     + (TenHundreds.NUMBER * 1000)
  34.     + (Hundreds.NUMBER * 100)
  35.     + (Tens.NUMBER * 10)
  36.     + Ones.NUMBER AS NUMBER
  37.  
  38. FROM SimpleDigits AS Ones
  39.     CROSS JOIN SimpleDigits AS Tens
  40.         CROSS JOIN SimpleDigits AS Hundreds
  41.             CROSS JOIN SimpleDigits AS TenHundreds
  42.                 CROSS JOIN SimpleDigits AS TenThousands
  43.                     CROSS JOIN SimpleDigits AS HundredThousands
  44.                         CROSS JOIN SimpleDigits AS Millions
  45.  
  46. )
  47.  
  48. -- Добавляем числа в таблицу
  49. INSERT dbo.[Random Numbers](RESULT)
  50.     SELECT ABS(CHECKSUM(NewId())) % 100000 AS RESULT
  51. FROM Digits
  52. WHERE NUMBER < 10000000
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top