MySQL Forums
Forum List  »  Newbie

How to insert sequential number in primary row
Posted by: muhammad ramzan
Date: April 22, 2024 12:09AM

Hello,
How to insert sequential number in primary row
I have created a table and created 2 columns in it.
And after that I saved 6 records in it.
Which looks something like this.
+.......+...................+
+ id + Name +
+.......+...................+
+ 1 + name number 1 +
+ 2 + name number 2 +
+ 3 + name number 3 +
+ 4 + name number 4 +
+ 5 + name number 5 +
+ 6 + name number 6 +
+.......+...................+
After that I deleted 2 records.
Which looks something like this.
+.......+...................+
+ id + Name +
+.......+...................+
+ 1 + name number 1 +
+ 2 + name number 2 +
+ 4 + name number 4 +
+ 6 + name number 6 +
+.......+...................+
When I insert a new record it saves the record under AUTO_INCREMENT=7.
Which looks something like this.
+.......+...................+
+ id + Name +
+.......+...................+
+ 1 + name number 1 +
+ 2 + name number 2 +
+ 4 + name number 4 +
+ 6 + name number 6 +
+ 7 + name number 7 +
+.......+...................+
Whereas I want to automatically reset the id number from the first row to 1 whenever I delete a record.
Which looks something like this.
+.......+...................+
+ id + Name +
+.......+...................+
+ 1 + name number 1 +
+ 2 + name number 2 +
+ 3 + name number 4 +
+ 4 + name number 6 +
+ 5 + name number 7 +
+.......+...................+
How can it be.
Thanks

Options: ReplyQuote


Subject
Written By
Posted
How to insert sequential number in primary row
April 22, 2024 12:09AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.