Jeffrey Williams (7/12/2009)
GilaMonster (7/12/2009)
If you want to delete the oldest rows, then you need something like this (because order by is not permitted in a delete statement)
DELETE FROM SomeTable WHERE PrimaryKeyColumn IN (SELECT TOP (200) PrimaryKeycolumn FROM SomeTable ORDER BY SomeDate)
Or, you identify the oldest rows by your date column instead of order:
DELETE TOP (200)
FROM SomeTable
WHERE datecolumn <= {some date limiter};
True, but that will delete 200 rows older than a certain date, not necessarily the oldest 200 rows in the table. Depends which is needed.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability