Interview Scenario on MySQL:

Interview Scenario on MySQL:
There is a table named SAMPLE, and we want to delete all the data from the
table. Which is better option?

  1. delete * from SAMPLE
  2. truncate table SAMPLE

In delete cursor is on the current location, data is deleted from the table but memory is not released by the table, by which searching and sorting operation may take so much time.

While, in truncate cursor is on the starting location, data is deleted permanently and memory is released for other entries, by which searching and sorting operation does not take so much time than delete the data by delete command.

to delete all records 2 is best (only if there is not any other effect related to primary key).

to delete few records 1 is best.