Search code examples
mysqldelete-row

How to Permanently Delete Table Data


I have table that have 4 fields. i.e. 1. id : Primary key, Auto Increment , 2. name, 3. salary, 4. designation.

when I add data id increments automatically. Suppose when I remove or delete row that have id = 15 i.e. last record and after that if I add new record then id starts from 16. So that is my problem, when I remove record It should be permanently removed. and id starts from 15 again.

Any suggestion for it ?


Solution

  • The purpose of the Primary Key on a table on RDBMS is to uniquely identify a record FOREVER. Even if you delete this record, its id "remains there" forever. The world needs to know that the record with id e.g. 15, existed once, but does not exist anymore. You should not be reusing primary keys that have been deleted. It is a wrong business and technical approach. You will get into much trouble.