Collections:
RAND() - Generating Random Numbers in SQL Server
How To Generate Random Numbers with the RAND() Function in SQL Server Transact-SQL?
✍: FYIcenter.com
Random numbers are very useful for generating test data, passwords, or other security related data. SQL Server 2005 offers you the random number generator function RAND in two format:
Note that calling RAND(seed) with the same seed will start the same sequence and return the same number. To avoid this repeating pattern, you should always call RAND() without any seed and let the server to randomly pickup a sequence.
The tutorial exercise below shows some good examples on how to generate random numbers:
SELECT RAND(100), RAND(), RAND(); -- new sequence SELECT RAND(100), RAND(), RAND(); -- same sequence again SELECT RAND(), RAND(), RAND(); SELECT RAND(), RAND(), RAND(); GO 0.715436657367485 0.28463380767982 0.0131039082850364 0.715436657367485 0.28463380767982 0.0131039082850364 0.28769876521071 0.100505471175005 0.292787286982702 0.868829058415689 0.370366365964781 0.58334760467751 -- Random integer between 0 and 100 SELECT FLOOR(100*RAND()); SELECT FLOOR(100*RAND()); SELECT FLOOR(100*RAND()); SELECT FLOOR(100*RAND()); GO 68 29 20 82
⇒ Character Strings and Binary Strings in SQL Server Transact-SQL
⇐ ROUND() - Rounding Values to Specific Precisions in SQL Server
⇑ Numeric Expressions and Functions in SQL Server Transact-SQL
2017-03-11, 6320🔥, 0💬
Popular Posts:
How to set the current database in SQL Server? Once you are connected to the SQL Server, you should ...
How To Connect the Oracle Server as SYSDBA in Oracle? This is Step 4. The best way to connect to the...
Where to find answers to frequently asked questions on INSERT, UPDATE and DELETE Statements in MySQL...
How to execute statements in loops in SQL Server Transact-SQL? How to use WHILE ... loops? You can u...
How To Enter Unicode Character String Literals in SQL Server Transact-SQL? Unicode characters are mu...