In this article, I am sharing how you can achieve it.
Idea here is to generate another column in "SELECT" statement that gives you random values for each row each time the query is executed.
CREATE TABLE TAB ( ID VARCHAR(10), NAME VARCHAR(10) ) GO INSERT INTO TAB SELECT 1, 'Anil' UNION ALL SELECT 2, 'Sunil' UNION ALL SELECT 3, 'Amit' UNION ALL SELECT 4, 'Sumit' UNION ALL SELECT 5, 'Rajesh'
SELECT RAND() AS RAND, NEWID() AS NEWID, ID, NAME FROM TAB
Check the result, you will find RAND() function is giving static value for each row but NEWID() is giving random values, so NEWID() is going to help us in getting random row numbers. Now, Lets see how we can use NEWID() to generate the random() values
SELECT ABS(CHECKSUM(NEWID())%100) AS NEWID, ID, NAME FROM TAB