Magento – manually close order

Sometimes there is no other way of completing an order than through SQL:

@orderId = 'XXXX'; # XXX is the order_id
UPDATE sales_flat_order SET state="canceled", status="canceled" WHERE entity_id = @orderId;

Instead of canceling an order You could delete it:

@orderId = 'XXXX';  # XXX is the order_id
SET FOREIGN_KEY_CHECKS = 1;
DELETE FROM sales_flat_order WHERE increment_id = @orderId;
DELETE FROM sales_flat_quote WHERE reserved_order_id = @orderId;