Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

Insira N valores aleatórios na tabela


Sem loops, uma inserção
;WITH cte AS
(  --there are easier ways to build a numbers table
   SELECT
       ROW_NUMBER() OVER (ORDER BY (select 0)) AS rn
   FROM
      sys.columns c1 CROSS JOIN sys.columns c2 CROSS JOIN sys.columns c3
)
INSERT INTO [T1] ([Value])
OUTPUT INSERTED.ID INTO T2  -- direct insert to T2
SELECT RAND(CHECKSUM(NEWID()))
FROM cte
WHERE rn <= @N;