MySQL Deleting Multiple Records
I have a database with a bunch of shops and once a month someone sends me a spreadsheet with the cancellations for that month so I need to delete 30-40 shops each mont开发者_Go百科h.
Is there a quick way to do it? Right now I just manually go in and delete them because sometimes there is only 8-10 but this last spreadsheet had a bunch and I would love to make this process a lot faster.
Depending on how technical you want to get, you could create an process that takes your spreadsheet as an input and deletes the ones listed in there. It would then be advisable to keep the spreadsheet structure the same every time.
Otherwise, you could simply use a SQL statement as such
delete from stores where store_id in (:ids);
or
delete from stores where store_name in (:names);
and manually copy the list of store IDs or names as a comma delimited list where the :variable is. If you are using names, just be sure each name is enclosed with ' .
It depends on whether these shops has something in common that let you classify them. In MySql, the syntax is DELETE FROM tableName WHERE condition;
where tableName
is the name of the table where you are going to perform the DELETE
query, and condition
is a boolean expression that tells the DBMS how to classify them: i.e:
DELETE FROM shop WHERE NOW() - last_activity > 7;
That would eliminate shops that have been inactive for more than a week.
精彩评论