Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

truncate table taking very long time, is it normal?

Tags:

I am using truncate table table_name; on a table with around 1 million rows, but it's been taking too long, running since last 3 hours.

Is it normal? Can you suggest some other way to delete all rows from a table, which could be faster?

like image 934
smrati katiyar Avatar asked Jul 20 '13 12:07

smrati katiyar


1 Answers

Truncate wont work in some cases such as ,

when you have index kind of things and some foreign key constraints

Easy way i suggest is

RENAME TABLE table_name TO t1;

CREATE TABLE table_name LIKE t1;

DROP TABLE t1;

or you can also use DELETE FROM table_name;

like image 117
Kalaiarasan Manimaran Avatar answered Sep 22 '22 00:09

Kalaiarasan Manimaran