I want to delete order in admin panel.
How it possible?
Please give me solution.
I used Magento 1.9.
you can use this extension
a link
I have tried this its work good.
You need to install extension which is appropriate to Delete orders.
From Magento you can have Delete Orders Extension. Try it.
You Can use DELETE ORDER extension which is available in magento store, with this extension you can easily manage and delete order.
Firstly I have to alert you to be cautious with this mode because it will delete all the orders without differentiating between test orders with actual ones. So if you, specifically owners of new stores, are considering using this way, please make sure all orders are your unwanted, and no actual orders are in your store, and I suggest that you should take a thorough backup before doing this.
Now, here are the steps for you to follow:
Step 1: Log on PhpMyAdmin
Step 2: Run SQL Query
Here are the queries you need to add in your database to delete all orders:
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;
— lets 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;
— Now, lets Reset all ID counters
TRUNCATE eav_entity_store;
ALTER TABLE eav_entity_store AUTO_INCREMENT=1;
SET FOREIGN_KEY_CHECKS=1;
When finished, all orders are deleted in your site!
Related
I am trying to temporarily disable foreign key checks, but have not been successful.
```
SET FOREIGN_KEY_CHECKS=0;
DROP TABLE IF EXISTS `menu_items`;
CREATE TABLE `menu_items` (
...
SET FOREIGN_KEY_CHECKS = 1;
```
It keeps telling me that I cannot delete or update a parent row. Any help would be appreciated!
To disable foreign key constraints when you want to truncate a table:
Use FOREIGN_KEY_CHECKS
SET FOREIGN_KEY_CHECKS=0;
Or you can use DISABLE KEYS:
ALTER TABLE table_name DISABLE KEYS;
I have this table:
CREATE TABLE table1 (
//..
UNIQUE KEY `UNIQ_60349993F97DBD80` (`contrat_parent_id`)
//..
)ENGINE=InnoDB AUTO_INCREMENT=4384 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci.
I try this statement:
alter table table drop index UNIQ_60349993F97DBD80
But it doesn't work. I try many statements, but, they don't work.
Can I help me ?
Just remove ALTER TABLE from the begging of your statement, and also add the table Name on the end.
drop index UNIQ_60349993F97DBD80 ON table1
Reference
I have the following constraint in CREATE statement:
UNIQUE (`field_name`)
These commands to remove constraint work in MySQL but not in H2:
DROP INDEX `field_name` ON `table_name`;
ALTER TABLE `table_name` DROP INDEX `field_name`;
I need a command which would work both in MySQL and H2 (MySQL is used in real environment and H2 in Unit tests)
Found the following workaround: removing column removes the constraint, so:
ALTER TABLE `table_name` ADD COLUMN `tmp_code` VARCHAR(50) NOT NULL DEFAULT 'TMP';
UPDATE `table_name`
SET `tmp_code` = `field_name`;
ALTER TABLE `table_name` DROP COLUMN `field_name`;
ALTER TABLE `table_name` ADD COLUMN `field_name` VARCHAR(50) NOT NULL;
UPDATE `table_name`
SET `field_name` = `tmp_code`;
ALTER TABLE `table_name` DROP COLUMN `tmp_code`;
Do SHOW CREATE TABLE to see the name of the UNIQUE KEY. Then you can proceed with the DROP or ALTER. It will probably say
UNIQUE KEY `col` (`col`),
The first col is the key name.
If you need to maintain the INDEX but get rid of the UNIQUEness constraint, then drop the key, then add a non-unique key.
I have a big MySQL InnoDB table having 5 million rows. I need to add a column to the table which will have a default int value.
What is the best way to do it? The normal alter table command appears to take a lot of time. Is there any better way to do it? Basically I want to know if there is any faster way or efficient way of doing it.
And if the table has foreign key references, is there any way other than alter table to do this?
Any help appreciated.
I would not say this is a better way, but ... You could create a separate table for the new data and set it up as foreign key relationship to the existing table. That would be "fast", but if the data really belongs in the main table and every (or most) existing records will have a value, then you should just alter the table and add it.
Suppose the table looked like this:
CREATE TABLE mytable
(
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(25),
PRIMARY KEY (id),
KEY name (name)
);
and you want to add an age column with
ALTER TABLE mytable ADD COLUMN age INT NOT NULL DEFAULT 0;
You could perform the ALTER TABLE in stages as follows:
CREATE TABLE mytablenew LIKE mytable;
ALTER TABLE mytablenew ADD COLUMN age INT NOT NULL DEFAULT 0;
INSERT INTO mytablenew SELECT id,name FROM mytable;
ALTER TABLE mytable RENAME mytableold;
ALTER TABLE mytablenew RENAME mytable;
DROP TABLE mytableold;
If mytable uses the MyISAM Storage Engine and has nonunique indexes, add two more lines
CREATE TABLE mytablenew LIKE mytable;
ALTER TABLE mytablenew ADD COLUMN address VARCHAR(50);
ALTER TABLE mytablenew DISABLE KEYS;
INSERT INTO mytablenew SELECT id,name FROM mytable;
ALTER TABLE mytable RENAME mytableold;
ALTER TABLE mytablenew RENAME mytable;
DROP TABLE mytableold;
ALTER TABLE mytable ENABLE KEYS;
This will let you see how many seconds each stage takes. From here, you can decide whether or not a straightforward ALTER TABLE is better.
This technique gets a little gory if there are foreign key references.
Your steps would be
SET UNIQUE_CHECKS = 0;
SET FOREIGN_KEY_CHECKS = 0;
Drop the foreign key references in mytable.
Perform the ALTER TABLE in Stages
Create the foreign key references in mytable.
SET UNIQUE_CHECKS = 1;
SET FOREIGN_KEY_CHECKS = 1;
Give it a Try !!!
Given the table created using:
CREATE TABLE tbl_Country
(
CountryId INT NOT NULL AUTO_INCREMENT,
IsDeleted bit,
PRIMARY KEY (CountryId)
)
How can I delete the column IsDeleted?
ALTER TABLE tbl_Country DROP COLUMN IsDeleted;
Here's a working example.
Note that the COLUMN keyword is optional, as MySQL will accept just DROP IsDeleted. Also, to drop multiple columns, you have to separate them by commas and include the DROP for each one.
ALTER TABLE tbl_Country
DROP COLUMN IsDeleted,
DROP COLUMN CountryName;
This allows you to DROP, ADD and ALTER multiple columns on the same table in the one statement. From the MySQL reference manual:
You can issue multiple ADD, ALTER, DROP, and CHANGE clauses in a single ALTER TABLE statement, separated by commas. This is a MySQL extension to standard SQL, which permits only one of each clause per ALTER TABLE statement.
Use ALTER TABLE with DROP COLUMN to drop a column from a table, and CHANGE or MODIFY to change a column.
ALTER TABLE tbl_Country DROP COLUMN IsDeleted;
ALTER TABLE tbl_Country MODIFY IsDeleted tinyint(1) NOT NULL;
ALTER TABLE tbl_Country CHANGE IsDeleted IsDeleted tinyint(1) NOT NULL;
To delete a single column:
ALTER TABLE `table1` DROP `column1`;
To delete multiple columns:
ALTER TABLE `table1`
DROP `column1`,
DROP `column2`,
DROP `column3`;
You can use
alter table <tblname> drop column <colname>
ALTER TABLE `tablename` DROP `columnname`;
Or,
ALTER TABLE `tablename` DROP COLUMN `columnname`;
If you are running MySQL 5.6 onwards, you can make this operation online, allowing other sessions to read and write to your table while the operation is been performed:
ALTER TABLE tbl_Country DROP COLUMN IsDeleted, ALGORITHM=INPLACE, LOCK=NONE;
Use ALTER:
ALTER TABLE `tbl_Country` DROP COLUMN `column_name`;
ALTER TABLE tbl_Country DROP columnName;
It is worth mentioning that MySQL 8.0.23 and above supports Invisible Columns
CREATE TABLE tbl_Country(
CountryId INT NOT NULL AUTO_INCREMENT,
IsDeleted bit,
PRIMARY KEY (CountryId)
);
INSERT INTO tbl_Country VALUES (1, 1), (2,0);
ALTER TABLE tbl_Country ALTER COLUMN IsDeleted SET INVISIBLE;
SELECT * FROM tbl_Country;
CountryId
1
2
ALTER TABLE tbl_Country DROP COLUMN IsDeleted;
db<>fiddle demo
It may be useful in scenarios when there is need to "hide" a column for a time being before it could be safely dropped(like reworking corresponding application/reports etc.).