/    Sign up×
Community /Pin to ProfileBookmark

Simple Mysql question…

How can I stop the auto increment just keep going up? How can I make it so it counts the amount of rows instead?

For example, if I had 3 rows (auto increments up to 3) and then decided to delete number 3, I want the auto increment to be 3 next time (because now theres only 2 rows left and 3 should be the next in the sequence) but instead 4 will be the next increment.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@Chris_JJun 15.2007 — Just run the following sql query:

[code=php]ALTER TABLE tablename AUTO_INCREMENT = 3[/code]
Copy linkTweet thisAlerts:
@r_soleauthorJun 15.2007 — hmm alright. Thanks
Copy linkTweet thisAlerts:
@MichaelttkkJun 16.2007 — another possible solution I have been using is, you delete the autoincremented no/number and recreated it.

example, no firstname lastname (the table structure)

delete the no

then, recreated the no again(autoincremented etc.) before the firstname
×

Success!

Help @r_sole spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...