Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There is a way to generate a list of GUID's using NEWID function?

I need to create a list of GUID's in SQL Server 2008 R2 and I am using the NEWID() function.

This is what I am trying but I just get only one ID:

SELECT TOP 100 NEWID() 

I am new to SQL Server and I don't know if there is a way to do that or a way to create a loop for do it.

I don't need to persist those GUID's I just want to show them on screen.

like image 278
ianaya89 Avatar asked Dec 09 '14 15:12

ianaya89


1 Answers

You can use an arbitrary table as "sequence-generator":

SELECT TOP (100) Guid = NEWID() 
FROM [master]..spt_values;

Demo

Note that this table contains only 2346 rows.

Worth reading: Generate a set or sequence without loops

like image 97
Tim Schmelter Avatar answered Oct 20 '22 18:10

Tim Schmelter