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