Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete from a table based on date [closed]

Tags:

sql-server

Can anyone help me with the script which will delete the data older than the particular date.

Thanks

like image 845
user70636 Avatar asked Apr 29 '09 20:04

user70636


People also ask

Can we delete a row from a table based on another table?

Deleting rows based on another table. Sometimes we need to delete rows based on another table. This table might exist in the same database or not. We can use the table lookup method or SQL join to delete these rows.

What is the fastest way to delete the data of a table?

TRUNCATE TABLE is functionally identical to DELETE statement with no WHERE clause: both remove all rows in the table. But TRUNCATE TABLE is faster and uses fewer system and transaction log resources than DELETE.


1 Answers

delete from YOUR_TABLE where your_date_column < '2009-01-01'; 

This will delete rows from YOUR_TABLE where the date in your_date_column is older than January 1st, 2009. i.e. a date with 2008-12-31 would be deleted.

like image 118
Pablo Santa Cruz Avatar answered Oct 10 '22 04:10

Pablo Santa Cruz