Sqlserver
 sql >> Datenbank >  >> RDS >> Sqlserver

Fügen Sie N zufällige Werte in die Tabelle ein

Keine Schleifen, eine Einlage

;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;