sdc248
asked on
Query help - delete all but 50 rows of data
Hi:
What is the fastest way to delete all but 50 rows of data from a database table? Thanks.
What is the fastest way to delete all but 50 rows of data from a database table? Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks guys. The "truncate table" command helps a lot. The old "delete from mytable where" method took forever to delete data from a couple of huge tables (200 million rows) and eventually failed because the transaction log grew rapidly and fill up the server. Luckily these huge tables don't have identity columns or foreign keys.
Delete From myTable Where myPK Not In (Select Top (50) myPK From myTable)