How to Delete Test Orders from Magento

Deleting your test orders currently requires running a script directly on your Database. Make sure you fully backup your database before doing anything! This script will delete all orders in the database and reset all order counters!

SET FOREIGN_KEY_CHECKS=0;

TRUNCATE `sales_order`;
TRUNCATE `sales_order_datetime`;
TRUNCATE `sales_order_decimal`;
TRUNCATE `sales_order_entity`;
TRUNCATE `sales_order_entity_datetime`;
TRUNCATE `sales_order_entity_decimal`;
TRUNCATE `sales_order_entity_int`;
TRUNCATE `sales_order_entity_text`;
TRUNCATE `sales_order_entity_varchar`;
TRUNCATE `sales_order_int`;
TRUNCATE `sales_order_text`;
TRUNCATE `sales_order_varchar`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;

ALTER TABLE `sales_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;

-- reset customers
TRUNCATE `customer_address_entity`;
TRUNCATE `customer_address_entity_datetime`;
TRUNCATE `customer_address_entity_decimal`;
TRUNCATE `customer_address_entity_int`;
TRUNCATE `customer_address_entity_text`;
TRUNCATE `customer_address_entity_varchar`;
TRUNCATE `customer_entity`;
TRUNCATE `customer_entity_datetime`;
TRUNCATE `customer_entity_decimal`;
TRUNCATE `customer_entity_int`;
TRUNCATE `customer_entity_text`;
TRUNCATE `customer_entity_varchar`;
TRUNCATE `log_customer`;
TRUNCATE `log_visitor`;
TRUNCATE `log_visitor_info`;

ALTER TABLE `customer_address_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `log_customer` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor_info` AUTO_INCREMENT=1;

-- Reset all ID counters
TRUNCATE `eav_entity_store`;
ALTER TABLE  `eav_entity_store` AUTO_INCREMENT=1;

SET FOREIGN_KEY_CHECKS=1;

36 comments for How to Delete Test Orders from Magento

Thatcher Michelsen - RichAgent.com's picture

Hey thanks for sharing this!...

Hey thanks for sharing this! huge help. I am learning about Magento now and am stoked about how powerful and feature rich it is, especially for how young of a platform it is. I will be checking out the rest of your blog thanks again! p.s. I came here from Noupe.com

Rock on.

Richard's picture

Thanks dude!...

Thanks dude!

Robert Readman's picture

Is this SQL Query still valid...

Is this SQL Query still valid for Magento? new Log_Visitor tables got added in version 1.3.1.1, so I don't this this query will still do it all 100%, it certainly removes the test orders in 1.3.2.2. Just don't want it missing anything.

Please take a little look.
Thanks,
Rob.

Richard's picture

Hey Robert, I’m not sure… You...

Hey Robert, I’m not sure… You can obviously check if table exists before running the queries.

Ray Bogman's picture

Well check this, a total...

Well check this, a total solution for deleting Magento order “Delete Any Order”

https://www.yireo.com/software/delete-any-order

Alexa's picture

Excellent! It works! Mag....

Excellent!
It works!

Mag. ver. 1.3.2.4

kerja keras's picture

thanks for the tips, its...

thanks for the tips, its helpful.

Richard's picture

Anytime!...

Anytime!

David's picture

Thank you so much. Worked...

Thank you so much. Worked great.

Richard's picture

Thanks!...

Thanks!

oliver's picture

works greet¡¡ thx 4 sharing,...

works greet¡¡ thx 4 sharing, but how to export only product, category and attributes in sql mode?

thx

Pierre's picture

Thank you very much! This has...

Thank you very much! This has helped me sort out a huge bug in a client's shop.

Richard's picture

Pierre, No Worries! Thanks...

Pierre, No Worries! Thanks for reading! Smile

sy's picture

thanks! works perfectly...

thanks! works perfectly

Richard's picture

Awesome!...

Awesome!

Jelle Henkens's picture

the table "sales_order_tax"...

the table "sales_order_tax" should also be cleaned, otherwise you get duplicate tax reported in your backend reports and on the sales order detail page.

Richard's picture

Jelle, Thanks for sharing...

Jelle, Thanks for sharing that!

brian's picture

Can you please explain how to...

Can you please explain how to delete a single order(with increment_id available)?

Shawngo's picture

Spankin' Fantabulous! Much...

Spankin' Fantabulous! Much thanks.

Richard's picture

Thanks!...

Thanks!

taslo's picture

You da man! Couldn't get any...

You da man! Couldn't get any easier than that.

Richard's picture

Thanks!...

Thanks!

Rajnikant's picture

thanks boss its amazing,...

thanks boss its amazing, helped me a lot...

Richard's picture

Awesome!...

Awesome!

Ingmar's picture

Wow wonderful, worked like a...

Wow wonderful, worked like a charm on 1.3.3
Thank you so much!

Jeff's picture

Hi does this work for 1.4x?...

Hi does this work for 1.4x?

Guru's picture

Manage Magento Orders by...

Manage Magento Orders by Orderbook Extension. visit
http://www.magentocommerce.com/magento-connect/Modulesoft+Solutions/exte...

Martin's picture

Since Magento changed to...

Since Magento changed to using flat sales order tables (1.4x) this doesn't work anymore Sad

Can you update ur SQL please Smile

Vinod's picture

Thanks, some one had posted...

Thanks, some one had posted it on magento forum, and also put the source site name which is your's thanks.

Vinod's picture

Is their any way by which we...

Is their any way by which we delete a particular order and reset the counter for that particular order. so that the test orders don't bother the order ID flow

Martin's picture

Here is the SQL for 4.x --...

Here is the SQL for 4.x


-- Reset Magento TEST Data
SET FOREIGN_KEY_CHECKS=0;

-- Reset dashboard search queries
TRUNCATE `catalogsearch_query`;
ALTER TABLE `catalogsearch_query` AUTO_INCREMENT=1;

-- Reset sales order info
TRUNCATE `sales_flat_creditmemo`;
TRUNCATE `sales_flat_creditmemo_comment`;
TRUNCATE `sales_flat_creditmemo_grid`;
TRUNCATE `sales_flat_creditmemo_item`;
TRUNCATE `sales_flat_invoice`;
TRUNCATE `sales_flat_invoice_comment`;
TRUNCATE `sales_flat_invoice_grid`;
TRUNCATE `sales_flat_invoice_item`;
TRUNCATE `sales_flat_order`;
TRUNCATE `sales_flat_order_address`;
TRUNCATE `sales_flat_order_grid`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sales_flat_order_payment`;
TRUNCATE `sales_flat_order_status_history`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_quote_payment`;
TRUNCATE `sales_flat_quote_shipping_rate`;
TRUNCATE `sales_flat_shipment`;
TRUNCATE `sales_flat_shipment_comment`;
TRUNCATE `sales_flat_shipment_grid`;
TRUNCATE `sales_flat_shipment_item`;
TRUNCATE `sales_flat_shipment_track`;
TRUNCATE `sales_invoiced_aggregated`;
TRUNCATE `sales_invoiced_aggregated_order`;
TRUNCATE `sales_order_aggregated_created`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;
ALTER TABLE `sales_flat_creditmemo` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_creditmemo_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_creditmemo_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_creditmemo_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_payment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_status_history` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_payment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_shipping_rate` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_track` AUTO_INCREMENT=1;
ALTER TABLE `sales_invoiced_aggregated` AUTO_INCREMENT=1;
ALTER TABLE `sales_invoiced_aggregated_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_aggregated_created` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;
SET FOREIGN_KEY_CHECKS=1;

Matt's picture

Thanks Martin!!!! I just used...

Thanks Martin!!!!

I just used your updated SQL for Magento 1.4.1.1.

It worked perfectly!

Ted's picture

Thanks Martin! Worked great...

Thanks Martin! Worked great for 1.4.1.1. I had to make a slight change to make it work in phpmyadmin for me. I just had to add "mgn_" in front of each of the databases to make it go through.

for example...


TRUNCATE `mgn_sales_flat_creditmemo`;
TRUNCATE `mgn_sales_flat_creditmemo_comment`;
TRUNCATE `mgn_sales_flat_creditmemo_grid`;

AlwaysHave's picture

Thanks Martin, worked like a...

Thanks Martin, worked like a charm.

Shyamji's picture

I Got Great Idea after seeing...

I Got Great Idea after seeing fantastic table concept for sales and order table ...

Thanks

Tiffany's picture

Hello, I am trying to delete...

Hello,

I am trying to delete test orders from the dashboard in magento. I am very new with this program and I am not sure how to back up and reset the database. I'm using godaddy - sql database but I am not sure how to do it.

I appreciate if someone can help me with this matter.

Thanks so much in Advance,

Tiffany.

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.