MySQL Auto-increment: Delete Record VS Truncate Table

preview_player
Показать описание
I thought to demonstrate a thing that some of you may not know, about how exactly auto-increment fields work, in MySQL example. What happens if you delete the record - will the next ID be the same?

- - - - -
Support the channel by checking out my products:

- - - - -
Other places to follow:
Рекомендации по теме
Комментарии
Автор

Thanks for the great tip in case of MySQL. Just wanted to mention that different dBs might have another syntax, f.ex. _alter sequence {tablename}_id_seq restart with {id}_ in case of PostgreSQL.

ruslanvoroshchukowlookitlt
Автор

wished there was a way using artisan for example :D ..
I used to change this manually in PHPmyadmin in : operations > table options > auto increment ..

mibrahim
Автор

I belive in using the uuid as primary key as trait. Any Suggestion ?

shaikhdanish
Автор

I thought there is an eloquent function that chain with delete() to reset auto increment so as the next record will have the id of deleted record

saydfuad
Автор

Why would we truncate instead of delete other than freeing the ID for other records?

PathOfDamn