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 - SQL Server Tutorial
From the course: Querying Microsoft SQL Server 2019
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
-
-
-
-
-
-
-
(Locked)
Use functions in T-SQL2m 47s
-
(Locked)
String functions3m 24s
-
(Locked)
Text concatenation3m 33s
-
(Locked)
Round with mathematical functions2m 46s
-
(Locked)
Work with date functions4m 53s
-
(Locked)
FORMAT date and times2m 59s
-
(Locked)
Return random records with NEWID2m 2s
-
(Locked)
The IIF logical function3m 9s
-
(Locked)
-
-
-
-
-