Truncate with condition

Sharpeye500 picture Sharpeye500 · Sep 14, 2010 · Viewed 127.8k times · Source

truncate ->this resets the entire table, is there a way via truncate to reset particular records/check conditions.

For ex: i want to reset all the data and keep last 30 days inside the table.

Thanks.

Answer

ceejayoz picture ceejayoz · Sep 14, 2010

No, TRUNCATE is all or nothing. You can do a DELETE FROM <table> WHERE <conditions> but this loses the speed advantages of TRUNCATE.