Right now I have my ID field as the primary key in MySQL and have AUTO_INCREMENT on. What I want to know is how to make the ID represent the number of that row in the table rather than giving it a number when it's inserted, then sticking with that number? Because when I delete something, then that number isn't used. I want them all to be unique based on row count.
Asked
Active
Viewed 320 times
1
-
Do You mean that You would like to reuse deleted ids? – Gustek Dec 06 '12 at 03:28
2 Answers
1
Always have a primary key. Either a basic auto increment int or a composite key of multiple fields. It helps your DB do it's job and comes in handy when you want to have relationships. Add a field called RowIndex
and renumber it when you delete anything.

Jeroen
- 4,023
- 2
- 24
- 40
0
When you create a table don't add the AUTO_INCREMENT key word
For existing table, use
ALTER TABLE <Table_Name> MODIFY COLUMN <Column_Name> INTEGER;
to remove the AUTO_INCREMENT and the Primary key will be kept.