Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete 75% Of a Table Randomly

Trying to make a smaller sample database but still have the data be somewhat statistically relevant. How can I delete x % of rows from the table ? Been fooling around with the NEWID() function.

like image 381
bumble_bee_tuna Avatar asked Jan 19 '14 01:01

bumble_bee_tuna


1 Answers

DELETE 
FROM TABLE_NAME
WHERE PK IN (SELECT TOP (75) PRECENT PK
             FROM TABLE_NAME
             ORDER BY NEWID())

Suggestion by Martin Smith

DELETE T 
FROM (SELECT TOP (75) PERCENT * 
      FROM TABLE_NAME 
      ORDER BY NEWID()) T
like image 80
M.Ali Avatar answered Oct 15 '22 16:10

M.Ali