Open links in new tab
    • Work Report
    • Email
    • Rewrite
    • Speech
    • Title Generator
    • Smart Reply
    • Poem
    • Essay
    • Joke
    • Instagram Post
    • X Post
    • Facebook Post
    • Story
    • Cover Letter
    • Resume
    • Job Description
    • Recommendation Letter
    • Resignation Letter
    • Invitation Letter
    • Greeting Message
    • Try more templates
  1. 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:

    SELECT
    ABS(CHECKSUM(NEWID())) % 100 + 1 AS RandomInt
    FROM sys.objects;
    Copied!

    Here, 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 10
    SELECT RAND() * 10 AS RandomFloat;

    -- Random integer between 0 and 10
    SELECT FLOOR(RAND() * 11) AS RandomInt;
    Copied!

    If you need different values per row, seed RAND() with a row-specific expression:

    SELECT
    RAND(CHECKSUM(NEWID())) AS RowRandomFloat
    FROM sys.objects;
    Copied!

    Generating bounded integers per row

    Feedback
  2. 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 MyTable
        SET MyColumn = (SELECT TOP 1 val
          FROM @randomStuff r
            INNER JOIN MyTable _MT
              ON 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 …

    • 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 …