if I truncate table in MySQL and after that, I insert a new row then the numbering of ID Column of row Starts from 1 or it will continue from last one record?????? if it will continue from the last record then how can I start from 1 after truncating the data.
Asked
Active
Viewed 734 times
0
-
1Does this answer your question? [Insert after truncate start from 1; but insert after delete resumes from previous value](https://stackoverflow.com/questions/42389511/insert-after-truncate-start-from-1-but-insert-after-delete-resumes-from-previou) – Ankit Jindal Jul 22 '20 at 15:34
1 Answers
1
Truncate table drops the existing rows, but does not reset the table metadata, which is where the auto increment counter is kept. If you want to restart the auto increment counter, you'll need do do so manually:
ALTER TABLE table_name AUTO_INCREMENT = start_value;
from:

PaulProgrammer
- 16,175
- 4
- 39
- 56
-
This is wrong on for at least 2 reasons 'Truncate operations drop and re-create the table,' and 'Any AUTO_INCREMENT value is reset to its start value.' https://dev.mysql.com/doc/refman/8.0/en/truncate-table.html#:~:text=Although%20TRUNCATE%20TABLE%20is%20similar,rather%20than%20a%20DML%20statement.&text=Truncate%20operations%20drop%20and%20re,so%20cannot%20be%20rolled%20back. You possibly meant delete – P.Salmon Jul 22 '20 at 16:20