SQL Server gets random data

Source: Internet
Author: User

1. One of the more common and useful

SELECT TOP Ten *, NEWID () as Random
From table
ORDER by random

The--NEWID function randomly generates a GUID, a long string, which we can use to take random numbers.

2. One of the more rapid ()

--declare @d Datetime
--set @d=getdate ()

SELECT Top 1* from users
where 0.01 >= cast (CHECKSUM (NEWID (), UID) & 0x7fffffff as float)/CAST (0x7fffffff as int)- - Here you can add conditions, such as and uid>10000000

The--& symbol indicates that the operation is performed by Bits, 0x7fffffff represents a hexadecimal number, and the conversion to decimal is 2147483647.
--select [Statement execution takes time (milliseconds)] = Datediff (Ms,@d,getdate ())

The Green Annotation section can query execution time, and the DateDiff function can return the difference between the second and third parameters, whichever is the result type defined by the first parameter, such as the current return in milliseconds

SQL Server gets random data

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.