SQL Server 2008 NEWID Function
In this article i will explain how to use the NEWID() function as random generator in SQL Server.
NEWID() function is used in generating random rows from a resultset in SQL Server database. We can also call it as SQL Random Generator. This function is used to select records randomly from a set of rows or from a table. Basic example for using this function is explained below.
Suppose we have table "Employee" with columns (ID, F_Name, L_Name, Salary, Region, City ) shown in below image.
Now to select records on random basis. Use TOP N keyword in select statement where NEWID() is in the ORDER BY statement.