- ✕This summary was generated using AI based on multiple online sources. To view the original source information, use the "Learn more" links.
In T-SQL, you can generate random values using RAND() or NEWID(). RAND() returns a pseudo-random float between 0 and 1 (exclusive), while NEWID() can be combined with functions like CHECKSUM() to produce per-row randomness.
Example – Random integer between 1 and 100 for each row:
SELECTABS(CHECKSUM(NEWID())) % 100 + 1 AS RandomIntFROM sys.objects;Copied!✕CopyHere, NEWID() ensures a different value per row, and % 100 + 1 scales it to 1–100.
Using RAND() for single or scaled values RAND([seed]) generates a float between 0 and 1. Without a seed, it changes per execution but not per row in the same query.
-- Random float between 0 and 10SELECT RAND() * 10 AS RandomFloat;-- Random integer between 0 and 10SELECT FLOOR(RAND() * 11) AS RandomInt;Copied!✕CopyIf you need different values per row, seed RAND() with a row-specific expression:
SELECTRAND(CHECKSUM(NEWID())) AS RowRandomFloatFROM sys.objects;Copied!✕CopyGenerating bounded integers per row
How can I insert random values into a SQL Server table?
Mar 31, 2015 · I'm trying to randomly insert values from a list of pre-defined values into a table for testing. I tried using the solution found on this StackOverflow question: When I I tried this, all of my …
- Reviews: 1
Code sample
UPDATE MyTableSET MyColumn = (SELECT TOP 1 valFROM @randomStuff rINNER JOIN MyTable _MTON M.Id = _MT.Id...Rand() and Newid() for SQL Random Numbers - SQL …
Jun 11, 2025 · Learn how to use the Rand () and Newid () functions in SQL Server to generate SQL random numbers and random data.
SQL Server RAND () Function - W3Schools
Definition and Usage The RAND () function returns a random number between 0 (inclusive) and 1 (exclusive). Syntax RAND (seed)
RAND (Transact-SQL) - SQL Server | Microsoft Learn
Nov 18, 2025 · You can generate a random integer value by scaling the RAND() function and combining it with the ROUND(), FLOOR(), or CEILING() functions. The following example returns a random integer …
SQL - SELECT RANDOM - GeeksforGeeks
Jul 23, 2025 · In this article, we’ve covered how to use the RANDOM () function (or its equivalent, RAND (), depending on the SQL dialect) to retrieve random rows …
Searches you might like
insert random value from predefined list of possible values
Apr 6, 2020 · My need is to insert random value from predefined list of possible values. It's data obfuscation project, thus no strict rules what value should be, rather it should be random.
sql server - Inserting random values into column - Database ...
Mar 28, 2019 · Rather than two steps you could define the initial values using a DEFAULT constraint on the new column. Find the answer to your question by asking. See similar questions with these tags. …
SQL Server: how to insert random integers into table?
To create a random integer number between two values (range), you can use the following formula: SELECT FLOOR (RAND ()* (b-a+1))+a; Where a is the smallest number and b is the largest number …
How to Generate a Random Number in the SQL Server …
With representative dataset formed with random numbers generated by SQL functions, data analysts and developers can test and validate their ideas. This …
Understanding the SQL Server RAND Function and Generating Random Values
Feb 17, 2025 · When working with SQL Server, there may be times when you need to generate random values. The RAND function in SQL Server allows you to generate a pseudo-random sequence of …