Thursday, May 21, 2009

Great simple tip on how to delete ordered data fast

SQLCAT team posted a simple yet elegant solution to an often-encountered problem during archiving or deleting the oldest data
http://sqlcat.com/msdnmirror/archive/2009/05/20/fast-ordered-delete.aspx

Great use of the "Can only use TOP in VIEW with ORDER BY" limit


CREATE VIEW v1 AS (SELECT TOP (10000) * FROM TABLE ORDER BY DATETIME)

--and we can delete the “top” rows using simply

DELETE FROM v1

No comments:

Post a Comment