How do I delete all entries I created today?

I am dealing with a very large database of ~ 6 million records. Today I added ~ 30,000 bad entries. How can I delete all records created today in MySQL?

+3


source to share


4 answers


It seems to be created_at

datetime. Try:

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

      



Of course, run select *

before running this query and make sure the data you intend to delete is the one you really want to delete.

+8


source


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



0


source


Try the following:

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

      

0


source


Condition

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

      

can be used to identify strings (and efficiently enough if there is an index on created_at

).

Make sure you back up the table (or better yet, the entire database) before dropping. Also, you can use some (temporary or temporary) table to store rows before deleting them from your table. Then you drop that temporary table when you're sure you've deleted 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 ;

      

0


source







All Articles