-- 44444444444444444444444

USE AdventureWorks
GO

-- 1 - Simple random value
SELECT RAND()
GO

-- 2 - Product name and the same random value
SELECT	TOP 5 [Name], 
		RAND() as RandomValue 
FROM Production.Product ORDER BY 2
GO

-- 3 - Random values based on the NEWID function
SELECT	TOP 5 [Name]
FROM Production.Product
ORDER BY NEWID()
GO

-- 4 - Table Sample with 1000 rows
SELECT * 
FROM Sales.SalesOrderDetail TABLESAMPLE (1000 ROWS)
GO

-- 5a - Total number of rows
SELECT COUNT(*) 
FROM Sales.SalesOrderDetail 
GO
-- 121317

-- 5b - Table Sample with 10 percent
SELECT * 
FROM Sales.SalesOrderDetail TABLESAMPLE (10 PERCENT)
GO

-- 6 - TOP gaurantees 250 rows are returned
SELECT TOP 250 * 
FROM Sales.SalesOrderDetail TABLESAMPLE (1000 ROWS)
GO

-- 7 - Use a large enough sample set to get a sufficient number of rows i.e. 1000 vs 100 rows
SELECT * 
FROM Sales.SalesOrderDetail TABLESAMPLE (100 ROWS)
GO

-- 8 - Same random data set with the REPEATABLE clause to return the same results for each execution
SELECT TOP 10 * 
FROM Sales.SalesOrderDetail TABLESAMPLE (1000 ROWS) REPEATABLE (25)
GO
