How to delete all records created today?

不问归期 提交于 2019-12-05 12:47:10

It seems created_at is a datetime. Try:

delete from table
where date(created_at) = curdate()

Of course, run a select * prior to run this query and make sure the data you're going to delete is the one you really want to delete.

DELETE FROM Table WHERE ( (DAY(CallDate) = DAY(GETDATE()) AND (MONTH(CallDate) = MONTH(GETDATE()) AND (YEAR(CallDate) = YEAR(GETDATE()) )

Try below:

delete from table
where left(created_at,10) =curdate()

The condition

WHERE created_at >= '2012-03-25' 
  AND created_at < '2012-03-26'

could be used to identify the rows (and quite efficiently if there is an index on created_at).

Before deleting, make sure you backup the table (or even better, the whole database). Additionally, you can use some (temp or permament) table to have the rows stored, before deleting them from your table. Then, you delete this temp table when you are sure you have erased the offending data - and nothing else:

CREATE TABLE wrong_data AS
  SELECT *
  FROM tableX
  WHERE created_at >= '2012-03-25' 
    AND created_at < '2012-03-26' ;

DELETE t
FROM tableX AS t
  JOIN wrong_data AS w
    ON w.PK = t.PK ;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!