SA-MP Forums Archive
MySQL IDs question - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Other (https://sampforum.blast.hk/forumdisplay.php?fid=7)
+--- Forum: Everything and Nothing (https://sampforum.blast.hk/forumdisplay.php?fid=23)
+--- Thread: MySQL IDs question (/showthread.php?tid=303841)



MySQL IDs question - iTorran - 15.12.2011

For each new row inserted into MySQL table, "ID" goes up by 1.
So e.g. if i add 5 rows.

ID: 1
ID: 2
ID: 3
ID: 4
ID: 5

But when i remove one.. e.g.

ID: 5

and add a new row, the ID of the new row is

ID: 6

So it goes:

ID: 1
ID: 2
ID: 3
ID: 4
ID: 6

Is there anyway to make it goto 5?
(if you know waht i mean)


Re: MySQL IDs question - Ricop522 - 15.12.2011

example:
pawn Код:
mysql_query("SELECT MAX(vehicleid) FROM vehicles");
    mysql_store_result();
    new SQL[20];
    mysql_fetch_row_format(SQL, "|");
    new sqlid = strval(SQL);
    mysql_free_result();
    format(string, sizeof(string), "ALTER TABLE `vehicles` AUTO_INCREMENT =%i", sqlid);
    mysql_query(string);



Re: MySQL IDs question - Sergei - 15.12.2011

Don't do that. It's not meant that game vehicleid is db vehicleid.


Re: MySQL IDs question - DRIFT_HUNTER - 15.12.2011

Its called Auto Increment and also you must set index to "PRIMARY"


Re: MySQL IDs question - Lorenc_ - 15.12.2011

pawn Код:
mysql_query("SELECT * FROM `player_data` ORDER BY `KILLS` DESC LIMIT 20");
- Selecting all lines from player_data
- Ordering it by kills
- In a descending format
- Limit is 20


Re: MySQL IDs question - XFlawless - 16.12.2011

Quote:
Originally Posted by iTorran
Посмотреть сообщение
For each new row inserted into MySQL table, "ID" goes up by 1.
So e.g. if i add 5 rows.

ID: 1
ID: 2
ID: 3
ID: 4
ID: 5

But when i remove one.. e.g.

ID: 5

and add a new row, the ID of the new row is

ID: 6

So it goes:

ID: 1
ID: 2
ID: 3
ID: 4
ID: 6

Is there anyway to make it goto 5?
(if you know waht i mean)
No you can't do that afaik. However if you have a PRIMARY KEY then you can fix the key ID by using ANALYSE TABLE table_name;