Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Truncate Statement Taking Too much time

I have a table Which has more than 1 million records, I have created a stored Procedure to insert data in that table, before Inserting the data I need to truncate the table but truncate is taking too long.

I have read on some links that if a table is used by another person or some locks are applied then truncate takes too long time but here I am the only user and I have applied no locks on that.

Also no other transactions are open when I tried to truncate the table.

As my database is on SQL Azure I am not supposed to drop the indexes as it does not allow me to insert the data without an index.

like image 862
Piyush Jain Avatar asked May 19 '26 00:05

Piyush Jain


1 Answers

Drop all the indexes from the table and then truncate, if you want to insert the data then insert data and after inserting the data recreate the indexes


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!