Atitit. Concurrency Test Solution (2) random sorting of random data sampled from random database records-----obtained
1. Application Scenario 1
2. Principle of random data extraction 1
3. Common implementation Methods : :: database random function 1
4. the implementation of Mssql NEWID () and rand () 1
5. the difference between newid () and rand () 2
6. NEWID () 2
7. Reference 2
1. Application Scenarios
Concurrency test
2. Random Data Extraction Principle
The principle is to loop all ID/record, append the random function number fields, and then sort as this field.
3. Common implementation methods::: Database Random function
Author:: Old Wow's paw attilax Ayron, email:[email protected]
Reprint please indicate source:Http://blog.csdn.net/attilax
4. The implementation of Mssql NEWID () and Rand ()
SELECT TOP 10 *
From Wechatuhstry
ORDER by NEWID ()
Or
Select Top *,newid () as random from Ywle where ywlename= ' 001 ' Ordey by Random
Random function: rand ()
Execute in Query Analyzer: Select rand (), you can see that the result is similar to a random decimal: 0.36361513486289558, a decimal like this is used in the actual application is not much, generally to take random numbers will take random integers. Let's look at the following two methods of randomly taking integers:
NEWID should be used instead of rand (). Newid each row is different .... Rand does not have the same number of times each time.
It returns a GUID
5. The difference between NEWID () and Rand ()
Select top 3 ID from Table order by NEWID () this one runs every time, producing a new random three-row result
The SELECT top 3 ID is the same as the three records of each time after it is run by the table order by Rand ()
The Rand () function returns the same value for all rows in the given command
You may not need to get such a result, you can provide a seed value to the rand () function. In the following code, we are given the ProductID of each row in the rand () function as the seed value.
6. NEWID ()
4650d5aa-e8fe-4721-83e7-ea12c4f7a473
It returns a GUID
Newdi () creates a unique value of type uniqueidentifier, similar to a style 6f9619ff-8b86-d011-b42d-00c04fc964ff
Because select invokes the function whenever a record is scanned, this results in a different value for each result record, which, if ordered by this value, resembles the effect of generating a random record
7. Reference
database query sorting using the random sort result example (Oracle_mysql_ms sql Server) _oracle_ script House . htm
SQL NEWID () random function - lansan log - netease blog . htm
random functions of SQL Server NewID () and RAND ()- unintentional - Blog Park . htm
SQL random function NEWID () and RAND ()-Xiao_mege log - netease blog . htm
The difference between newid () and rand () Small Talk - far away - Blog Park . htm
Atitit. Concurrency test Solution (2)-----Get random database records random sorting principle and implementation of random data sampling