A random-number function generates a pseudo-random value. The function name and returned range vary between database systems.
Random values can be useful when selecting sample records, testing applications, or creating randomized analytical datasets.
Generate a random value for each customer record.
SELECT
CustomerID,
RANDOM() AS RandomValue
FROM Customers;
Random functions can support sampling, testing, simulations, and randomized record selection.
- Random functions generate pseudo-random values.
- Function names vary by database.
- They can support data sampling.
- They are useful for testing.
- Random results are not always reproducible.
Why are random functions used in SQL?
They can be used for sampling, testing, simulations, and randomized record selection.
Is RANDOM syntax the same in every database?
No. Different databases provide different random-number functions.