Deleting Order and Customer Data with SQL

During the development and testing process we create different customer and different order in Magento , after the site goes live we need to delete that . So  here are the simple ways to do it with the query below

SET FOREIGN_KEY_CHECKS=0;

##############################
# SALES RELATED TABLES
##############################
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 `#_log_quote`;

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 `#_log_quote` AUTO_INCREMENT=1;

#########################################
# DOWNLOADABLE PURCHASED
#########################################
TRUNCATE `#_downloadable_link_purchased`;
TRUNCATE `#_downloadable_link_purchased_item`;

ALTER TABLE `#_downloadable_link_purchased` AUTO_INCREMENT=1;
ALTER TABLE `#_downloadable_link_purchased_item` AUTO_INCREMENT=1;

#########################################
# RESET ID COUNTERS
#########################################
TRUNCATE `#_eav_entity_store`;
ALTER TABLE  `#_eav_entity_store` AUTO_INCREMENT=1;

##############################
# CUSTOMER RELATED TABLES
##############################
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 `#_tag`;
TRUNCATE `#_tag_relation`;
TRUNCATE `#_tag_summary`;
TRUNCATE `#_tag_properties`;            ## CHECK ME
TRUNCATE `#_wishlist`;
TRUNCATE `#_log_customer`;

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 `#_tag` AUTO_INCREMENT=1;
ALTER TABLE `#_tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `#_tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `#_tag_properties` AUTO_INCREMENT=1;
ALTER TABLE `#_wishlist` AUTO_INCREMENT=1;
ALTER TABLE `#_log_customer` AUTO_INCREMENT=1;

##############################
# ADDITIONAL LOGS
##############################
TRUNCATE `#_log_url`;
TRUNCATE `#_log_url_info`;
TRUNCATE `#_log_visitor`;
TRUNCATE `#_log_visitor_info`;
TRUNCATE `#_report_event`;
TRUNCATE `#_report_viewed_product_index`;
TRUNCATE `#_sendfriend_log`;
### ??? TRUNCATE `#_log_summary`

ALTER TABLE `#_log_url` AUTO_INCREMENT=1;
ALTER TABLE `#_log_url_info` AUTO_INCREMENT=1;
ALTER TABLE `#_log_visitor` AUTO_INCREMENT=1;
ALTER TABLE `#_log_visitor_info` AUTO_INCREMENT=1;
ALTER TABLE `#_report_event` AUTO_INCREMENT=1;
ALTER TABLE `#_report_viewed_product_index` AUTO_INCREMENT=1;
ALTER TABLE `#_sendfriend_log` AUTO_INCREMENT=1;
### ??? ALTER TABLE `#_log_summary` AUTO_INCREMENT=1;

SET FOREIGN_KEY_CHECKS=1;

Customer detail can be deleted from the magento admin > Manage Customer.

http://www.magentocommerce.com/wiki/import-export_and_data_manipulation/deleting_order_and_customer_data_with_sql