Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should primary key ever be reset?

Not sure if this has already been answered, and this is kind of a dumb question, but I'm kinda new to using SQL in android and I've made a simple task app using the language. In the app, I added a feature to delete all tasks. When I create a new one, the primary key keeps counting up. Now, there's nothing wrong with the app or the code or anything, but if all the tasks are deleted, should I reset the primary key, or is it bad practice to do so? If not, will it ever become large enough to provoke a crash?

like image 234
ctcuff Avatar asked May 05 '26 10:05

ctcuff


1 Answers

I would generally keep it increment because it can simplify certain things like database backup/restores, and replication to other database nodes. It makes things more predictable when your rows are always unique by id.

like image 60
Oleksi Avatar answered May 07 '26 07:05

Oleksi