How to Get a Random Row From a SQL Database?
use this Quary
NEWID (Transact-SQL)
Applies to: SQL Server (SQL Server 2008 through current version).
Creates a unique value of type uniqueidentifier.
NEWID() is based on a combination of a pseudorandom number (from the clock) and the MAC address of the primary NIC.
However, inserting random numbers like this as the clustered key on a table is terrible for performance. You should consider either NEWSEQUENTIALID() or a COMB-type function for generating GUIDs that still offer the collision-avoidance benefits of NEWID() while still maintaining acceptable INSERT performance.
use this Quary
- select Top 5 Id from YourTable order by NEWID()
NEWID (Transact-SQL)
Applies to: SQL Server (SQL Server 2008 through current version).
Creates a unique value of type uniqueidentifier.
NEWID() is based on a combination of a pseudorandom number (from the clock) and the MAC address of the primary NIC.
However, inserting random numbers like this as the clustered key on a table is terrible for performance. You should consider either NEWSEQUENTIALID() or a COMB-type function for generating GUIDs that still offer the collision-avoidance benefits of NEWID() while still maintaining acceptable INSERT performance.
I got solution thanks
ReplyDelete