Atitit. Concurrent Test Solution (2) ----- obtain the random number of database records

Source: Internet
Author: User
Atitit. concurrent Test Solution (2) ----- obtain random database records and randomly extract data for random sorting 1. application Scenario 12. principle of random data extraction 13. common Implementation Methods: Database random functions 14. mssql implementation NEWID () and rand () 15. difference between newid () and rand () 26. NEWID () 27. refer to 21. application

Atitit. concurrent Test Solution (2) ----- obtain random database records and randomly extract data for random sorting 1. application Scenario 1 2. principle of random data extraction 1 3. common Implementation Methods: Database Random Functions 1 4. mssql implementation NEWID () and rand () 1 5. difference between newid () and rand () 2 6. NEWID () 2 7. refer to 2 1. application

Atitit. Concurrent Test Solution (2) ----- obtain random database records and randomly extract data for random sorting

1. Application Scenario 1

2. Principles of random data extraction 1

3. Common Implementation Methods: Database random function 1

4. Mssql implementation NEWID () and rand () 1

5. Differences between newid () and rand () 2

6. NEWID () 2

7. Refer to 2

1. application scenarios

Concurrency Test

2. Principles of random data extraction

The principle is to loop all the ID/record, append the random function field, and then sort the as field ..

3. Common Implementation Methods: Database Random Functions

Author: old wow's paw Attilax iron, EMAIL: 1466519819@qq.com

Reprinted please indicate Source: http://blog.csdn.net/attilax

4. Mssql implementation NEWID () and rand ()

Select top 10 *

FROM wechatuhstry

Order by newid ()

Or

Select top 10 *, newid () as Random from ywle where ywlename = '001' ordey by Random

Random Function: rand ()
Run select rand () in the query analyzer and you can see that the result is a random decimal like this: 0.36361513486289558. decimal places like this are not used much in practical applications, generally, random numbers are random integers. Let's look at the following two random integer acquisition methods:

Newid should be used instead of rand ()... newid is different in each row... rand is different in every number of times.

It returns a GUID

5. Differences between newid () and rand ()

Select top 3 id from table order by newid () each time this line is run, a new random three-row result is generated.

The three records of the select top 3 id from table order by Rand () operation are the same each time.

The Rand () function returns the same value for all rows in a given command.

If you do not need such a result, you can provide a seed value to the rand () function. In the following code, the productid of each row is given as the seed value in the Rand () function.

6. NEWID ()

4650D5AA-E8FE-4721-83E7-EA12C4F7A473

It returns a GUID

Newdi () creates a unique value of the uniqueidentifier type, similar to this style 6F9619FF-8B86-D011-B42D-00C04FC964FF
This function is called every time the select statement is scanned to obtain a record. In this way, different values of each result record are generated. Sorting by this value is similar to generating a random record.

7. Reference

Example of database query and sorting using random sorting results (Oracle_MySQL_MS SQL server_oracle_footfall .htm

SQL NEWID () random function-log of lansong-wangyi Boke .htm

SQL server's Random Functions newID () and RAND ()-unintentional-blog. htm

Log of the SQL Random Functions NEWID () and RAND ()-xiao_mege-wangyi Boke .htm

Differences between newid () and rand ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.