Guest User

Untitled

a guest
Jan 19th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. SELECT NEWID()
  2. GO 50
  3.  
  4. SELECT NEWID()
  5. FROM master..spt_values
  6. WHERE name IS NULL
  7. AND number < 50
  8.  
  9. SELECT TOP 50 NEWID() FROM master.dbo.sysobjects WHERE xtype = 'S'
  10.  
  11. --run these queries independently
  12. CREATE TABLE #temp1 (ID UniqueIdentifier)
  13. GO
  14.  
  15. INSERT INTO #temp1
  16. SELECT NewID() AS ID
  17. GO 50
  18.  
  19. SELECT *
  20. FROM #temp1
  21. GO
  22.  
  23. DROP TABLE #temp1
  24. GO
  25.  
  26. -- Static solution: only 5 GUID values
  27.  
  28. SELECT NEWID()
  29. FROM (VALUES(1), (2), (3), (4), (5)) AS Numbers(Number)
  30.  
  31. -- Dynamic solution
  32.  
  33. DECLARE @Num INT;
  34. SET @Num=5;
  35. SELECT TOP(@Num)
  36. NEWID()
  37. FROM sys.objects o;
  38.  
  39. -- Another dynamic solution
  40. --SET STATISTICS IO ON;
  41. --GO
  42.  
  43. DECLARE @Num INT;
  44. SET @Num=567;
  45.  
  46. WITH N10(Number)
  47. AS (
  48. SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL
  49. SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10
  50. ), N100(Number)
  51. AS (
  52. SELECT (a.Number-1)*10+b.Number
  53. FROM N10 AS a CROSS JOIN N10 AS b
  54. ), N1000(Number)
  55. AS (
  56. SELECT (a.Number-1)*100+b.Number
  57. FROM N100 AS a CROSS JOIN N100 AS b
  58. )
  59. SELECT TOP(@Num)
  60. NEWID() AS [GUID]
  61. FROM N1000;
Add Comment
Please, Sign In to add comment