From the course: Querying Microsoft SQL Server 2019

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Return random records with NEWID

Return random records with NEWID - SQL Server Tutorial

From the course: Querying Microsoft SQL Server 2019

Start my 1-month free trial

Return random records with NEWID

- [Instructor] Many statistical analyses operate on a significant subset of records rather than the entire dataset. And when you need to perform verification audits, you want to make sure that the records that you've chosen for review represent an unbiased random selection. You can use the SQL Server function NEWID to help you pull random records out of a data table for these kinds of analyses projects and audits. I'm going to start with a query that pulls out the ID numbers of all of the records in the WorkOrder table. The results of this query will show me all the different work orders that we have in the database. There's a total of 72,591 rows. Then I can add a new column to this query using the NEWID function. This function doesn't have any arguments, so I just type in an open parenthesis and a closing parenthesis. This'll simply generate a unique identifier for every row in the result. If you run the query…

Contents