SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 17/08/2019, 10:30 AM   #1
Libbyphay
Big Clucker
 
Join Date: May 2017
Posts: 188
Reputation: 0
Default Problem AUTO_INCREMENT

I have 10 Characters, the AUTO_INCREMENT = 11.

PHP Code:
ALTER TABLE `characters`
  
MODIFY `IDint(11NOT NULL AUTO_INCREMENTAUTO_INCREMENT=11
When I delete 1 or ,2 The AUTO_INCREMENT no use 1, 2.

How can I fix it.

Sorry my english so bad.
Libbyphay is offline   Reply With Quote
Old 17/08/2019, 10:46 AM   #2
Z3nx31L
Little Clucker
 
Join Date: Aug 2019
Posts: 31
Reputation: 0
Default Re: Problem AUTO_INCREMENT

What Do You Mean?
__________________

IND TEAM
Z3nx31L Is Here
Z3nx31L is offline   Reply With Quote
Old 17/08/2019, 11:01 AM   #3
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 662
Reputation: 96
Default Re: Problem AUTO_INCREMENT

I replied to this exact question few hours ago but apparently they decided to delete their thread.

So once again, auto increment makes sure in each row there is a unique identifier. Why do you want to do extra work to fill the gaps when the result will be the same?
Calisthenics is offline   Reply With Quote
Old 17/08/2019, 11:23 AM   #4
Libbyphay
Big Clucker
 
Join Date: May 2017
Posts: 188
Reputation: 0
Default Re: Problem AUTO_INCREMENT

Quote:
Originally Posted by Calisthenics View Post
I replied to this exact question few hours ago but apparently they decided to delete their thread.

So once again, auto increment makes sure in each row there is a unique identifier. Why do you want to do extra work to fill the gaps when the result will be the same?
Why not 0 1 2 3 4 5? I think it great.
Because if player no use, other player can use it.

Sorry my bad english.
Libbyphay is offline   Reply With Quote
Old 17/08/2019, 11:40 AM   #5
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,637
Reputation: 540
Default Re: Problem AUTO_INCREMENT

The ID is not an index like in an array, so just an artificial number and it doesn't really matter how big the number is.
This is also useful if you reference the ID somewhere else, if the character gets deleted that reference will be invalid instead of pointing to an unrelated character (that was prior used by the actual character it referenced) which can cause problems.
Furthermore everytime you delete a character you need to make sure to also check all other tables that reference this character. This is not the case if you just let auto increment do its work.

You could do a soft delete, so when a character gets deleted you just "reset" the row instead of deleting it, for example by setting the name to NULL or adding a new column to define whether or not a row is valid. You will probably need to change existing code to consider these rows as well (more work for no real advantage).

Then you can use something like
Code:
SELECT min(ID) where Name IS NULL
and it would select the lowest free index.

I wouldn't recommend doing so because it just adds extra work and the only advantage is basically cosmetic (the ID should only be used internally anyway so why would it matter if a character ID is 31 or 232 and a bunch of unused indexes in between?).
NaS is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
auto_increment help ,TomY' Scripting Help 1 11/07/2018 07:49 AM
MYSQL Data Problem auto_increment DandyCorleone Scripting Help 4 10/01/2017 03:37 AM
Need help with Auto_Increment MYSQL! dieuhanhphuc Scripting Help 2 15/07/2014 01:51 PM
sql query to find the last AUTO_INCREMENT CraftMan Scripting Help 1 30/09/2011 04:03 AM
Moving AUTO_INCREMENT down? Antonio [G-RP] Help Archive 0 14/02/2011 11:43 PM


All times are GMT. The time now is 11:30 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.