Tip #1
TABLESAMPLE clause - Select random records from table. It works by sampling the rows from query results.
Example - Randomly Select 5 Percent of Records. Below query based on table created in previous post
SELECT
EmployeeId,
EmployeeName,
DeptId
FROM Employee
TABLESAMPLE (5 PERCENT);
Observation - 5% records returned were contiguous / sequential records. For Generating test data from production this can be used.
IF OBJECT_ID ('Employee') IS NOT NULL DROP TABLE Employee
CREATE TABLE Employee
(
SSNNo uniqueidentifier DEFAULT NEWSEQUENTIALID() PRIMARY KEY WITH (FillFactor = 70),
EmployeeName CHAR(100) NOT NULL,
DeptId smallint NOT NULL,
CreatedDate DateTime NOT NULL,
ModifiedDate DateTime NOT NULL
)
No comments:
Post a Comment